Sunday, September 13, 2015

WiFi Without Network Manager Frippery

Back in my day, sonny…there was a time when you could make your networking work without the network manager applet. Not that I’m saying the NetworkManager program is bad, because it actually has been getting better. But the fact of the matter is that I’m a networking guy and a server guy, so I need keep my config-file wits sharp. So take out your pocket knife and let’s start to whittle.
Begin by learning and making some notes about your interfaces before you start to turn off NetworkManager. You’ll need to write down these 3 things:
1) Your SSID and passphrase.
2) The names of your Ethernet and radio devices. They might look like wlan0, wifi0, eth0 or enp2p1.
3) Your gateway IP address.
Next, we’ll start to monkey around in the command line… I’ll do this with Ubuntu in mind.
So, let’s list our interfaces:
  1. $ ip a show
Note the default Ethernet and wifi interfaces:
It looks like our Ethernet port is eth0. Our WiFi radio is wlan0. Want to make this briefer?
  1. $ ip a show | awk '/^[0-9]: /{print $2}'
The output of this command will look something like this:
Your gateway IP address is found with:
  1. route -n
It provides access to destination (everything). In the below image it is, which is perfectly nominal.
Let’s do a bit of easy configuration in our /etc/networking/interfaces file. The format of this file is not difficult to put together from the man page, but really, you should search for examples first.
Plug in your Ethernet port.
Basically, we’re just adding DHCP entries for our interfaces. Above you’ll see a route to another network that appears when I get a DHCP lease on my Ethernet port. Next, add this:

  1. auto lo
  2. iface lo inet loopback
  3. auto eth0
  4. iface eth0 inet dhcp
  5. auto wlan0
  6. iface wlan0 inet dhcp

To be honest, that’s probably all you will ever need. Next, enable and start the networking service:
  1. sudo update-rc.d networking enable

  1. sudo /etc/init.d/networking start
Let’s make sure this works, by resetting the port with these commands:
  1. sudo ifdown eth0

  1. sudo ip a flush eth0

  1. sudo ifup eth0
This downs the interface, flushes the address assignment to it, and then brings it up. Test it out by pinging your gateway IP: ping If you don’t get a response, your interface is not connected or your made a typo.
Let’s “do some WiFi” next! We want to make an /etc/wpa_supplicant.conf file. Consider mine:
  1. network={
  2. ssid="CenturyLink7851"
  3. scan_ssid=1
  4. key_mgmt=WPA-PSK
  5. psk="4f-------------ac"
  6. }
Now we can reset the WiFi interface and put this to work:
  1. sudo ifdown wlan0

  1. sudo ip a flush wlan0

  1. sudo ifup wlan0

  1. sudo wpa_supplicant -Dnl80211 -c /root/wpa_supplicant.conf -iwlan0 -B

  1. sudo dhclient wlan0
That should do it. Use a ping to find out, and do it explicitly from wlan0, so it gets it’s address first:

  1. $ ip a show wlan0 | grep "inet"
  1. $ ping -I
Presumably dhclient updated your /etc/resolv.conf, so you can also do a:
  1. ping -I
Well guess what – you’re now running without NetworkManager!

No comments:

Post a Comment