# Returning wlan to initial state



## kpedersen (Nov 20, 2012)

Hello,

I have been periodically searching for a solution to this but I am not sure it is even possible.

if I do a bunch of random things to my wireless interface like...


```
# ifconfig wlan0 ssid "somelan" up
# ifconfig wlan0 wepmode on wepkey "somekey"
# ifconfig wlan0 inet 192.168.1.1 netmask 255.255.255.0 up
```

Is there any way I can undo all this jibberish?

Currently I need to do something like


```
# ifconfig wlan0 ssid "" wepmode off wepkey "" down
```

I still havnt reset the inet or netmask yet either and it is a bit of a pain to have to do this, i.e when swapping from a wep or open network to a wpa one.

something like...


```
# ifconfig wlan0 returntonormal
```

Any ideas?


----------



## fonz (Nov 20, 2012)

kpedersen said:
			
		

> Is there any way I can undo all this jibberish?
> [snip]
> something like...
> 
> ...


As far as I know there's no returntonormal command, but you could of course figure out what the defaults are and then conjure up a script or alias to reset those. And although I haven't tested it, if the NIC driver is a module you could try to unload and reload it again. As I said I didn't test it but it may or may not reset the defaults.

Hope this helps (and perhaps someone else has a better idea),

Fonz

Edit: See bbzz's answer. I _should have_ thought of that, he _did_.


----------



## bbzz (Nov 20, 2012)

Wipe clean with
`# ifconfig wlan0 destroy`
and
`# ifconfig wlan0 create wlandev <device_name>`


----------



## kpedersen (Nov 20, 2012)

Hi, thanks bbzz this solution seems to work great 

I guess I am lucky that since FreeBSD 8.0, the wireless device needs to be aliased before use.

Would it be possible to do the same type of thing with a non aliased interface?

For example em0, ath0 etc...?


----------



## bbzz (Nov 21, 2012)

There's interface restart with 
`# /etc/rc.d/netif restart`

But that affects everything. Other than that, not sure.


----------



## mamalos (Nov 21, 2012)

bzzz, if I am not mistaken the command you've given can be followed by the interface's name (ie wlan0 in our case), but the truth is that I don't use it cause I am not very sure that it only touches the interface I am interested in.


----------



## cpm@ (Nov 21, 2012)

Remove assigned IP address from network interface:
[CMD=]# ifconfig <interface name> down delete[/CMD]


----------



## bbzz (Nov 21, 2012)

mamalos said:
			
		

> bzzz, if I am not mistaken the command you've given can be followed by the interface's name (ie wlan0 in our case), but the truth is that I don't use it cause I am not very sure that it only touches the interface I am interested in.



Correct, and, it does. Use 'wlanX' to 'delete' cloned interface. It only affects that interface, and it removes ALL configuration.

This also helps in a case when cloned interface start flapping up/down (check dmesg). Happens quite often, in fact.


----------

