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:

$ ip a show

Note the default Ethernet and wifi interfaces:
ip-a-show

It looks like our Ethernet port is eth0. Our WiFi radio is wlan0. Want to make this briefer?

$ ip a show | awk  '/^[0-9]: /{print $2}'

The output of this command will look something like this:

lo:
eth0:
wlan0:

Your gateway IP address is found with:

route -n

It provides access to destination 0.0.0.0 (everything). In the below image it is 192.168.0.1, which is perfectly nominal.

route-n
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.
interfaces
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:

 

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto wlan0
iface wlan0 inet dhcp

 

To be honest, that’s probably all you will ever need. Next, enable and start the networking service:

sudo update-rc.d networking enable

 

sudo /etc/init.d/networking start

Let’s make sure this works, by resetting the port with these commands:

sudo ifdown eth0

 

sudo ip a flush eth0

 

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 192.168.0.1. 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:

network={
ssid="CenturyLink7851"
scan_ssid=1
key_mgmt=WPA-PSK
psk="4f-------------ac"
}

Now we can reset the WiFi interface and put this to work:

sudo ifdown wlan0

 

sudo ip a flush wlan0

 

sudo ifup wlan0

 

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

 

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:

 

$ ip a show wlan0 | grep "inet"

192.168.0.45

$ ping -I 192.168.0.45 192.168.0.1

Presumably dhclient updated your /etc/resolv.conf, so you can also do a:

ping -I 192.168.0.45 www.yahoo.com

Well guess what – you’re now running without NetworkManager!

More great Linux goodness!

Jed Reynolds
Jed Reynolds has been known to void warranties and super glue his fingers together. When he is not doing photography or fixing his bike, he can be found being a grey beard programmer analyst for Candela Technologies. Start stalking him at https://about.me/jed_reynolds.

Leave a Reply

9 Comments on "WiFi Without Network Manager Frippery"

Notify of
Sort by:   newest | oldest | most voted
Daniel Sandman
Guest

This is a little bit deprecated nowadays though. Not many distros still use the SysV/Upstart ways of doing things. Nowadays you use systemd and preferable systemd-networkd. You pretty much only need two lines in a .network file and you are done. I did this a while back and it cut the time for connection from roughly 7-10 to 0.25-0.5 seconds. Speeding up the boot considerably.

matthartley
Guest

>Not many distros still use the SysV/Upstart ways of doing things.

This is a fair point, however I believe Jed wanted to provide a set of guidelines that worked across the board.
That said, the comments area is a fantastic place to share any alternatives so others can try out all the options. 🙂 Please feel free to post your solution below.

Daniel Sandman
Guest

He should have mentioned this because legacy distros is pretty much the only place it still apply. Systemd-networkd does work everywhere though.

In systemd-networkd the only thing you need for DHCP is:

nano /etc/systemd/network/MyDhcp.network

———————————-
[Match]
Name=en*

[Network]
DHCP=ipv4
———————————-

You do not need the device(s) name. A wild card like above for wired would work. Wireless need wpa_supplicant so that is a bit more demanding. Also.. ‘ip addr’ and ‘ip route’ is what I would have used.

Same thing but with static would be:

——————————–
/etc/systemd/network/wired.network

——————————–

[Match]
Name=enp1s0

[Network]
Address=192.168.1.2/24
Gateway=192.168.1.1
——————————-

Jed Reynolds
Guest

@danielsandman:disqus
I’m happy to see you post this example. From the standpoint of many people using Ubuntu 14.04 (e.g.) and CentOS 6, my article works well, and it also works on most command-lines for an ad-hoc networking solution.

Daniel Sandman
Guest

Yes, especially in Ubuntu’s case I know yours do.. they have still not transitioned fully from Upstart. Systemd are backward compatible with SysV so it will probably work awhile longer too. My point was though that even if that works the systemd-networkd do too.. and it will work on all distros running systemd. Which pretty much covers all the bigger ones. Also as this doesn’t work on all it should have been mentioned.

It’s still a great article… I just felt I had to mention this. 😉

Jed Reynolds
Guest
@danielsandman:disqus At Candelatech, we have been putting our software on recent Fedoras for many years, and a lot of our network emulation commands are all ‘ip’ based. A lot of this has to do with cross-distro compatibility. LANforge is still installed on CentOS6.x, runs on isolated Fedora fedora systems as old as F12, and on Ubuntu and Ubuntu LXDE live CDs. So that more fully informs us of my point of view. I would be interested to see what the possibilities for using systemd/networkd are because I know RH/Fedora has embraced that. (I doubt that the LANforge product could rely… Read more »
sk43999
Guest

One would still like to understand what is behind all those commands. Best book I read on networking underpinnings was Richard Stevens “TCP/IP Illustrated Vol 1” – albeit written before the days of wireless, so commands like “wpa_supplicant” are not explained. I never liked the “network-manager” GUI utility, so I wrote my own. It comes with an iconic button: “I’m Feeling Lucky”. Very useful.

Daniel Sandman
Guest

NetworkManager do have a cli tool too… but if you know what you need it is a lot of cruft. 😉

IJK
Guest

More to the point: somebody has to know how to do these things. The Network Manager does not do them by magic.

wpDiscuz