Skip to content

Manual network setup on Linux

jameshofstra edited this page Apr 4, 2017 · 5 revisions

NetworkManager is good at figuring out the correct network settings most of the time, but sometimes you may have to configure the network by hand.

Before you begin

You will need root permission to run most of the following commands. Log in as root, or prefix commands with sudo where applicable.

Make sure NetworkManager is terminated before you attempt the steps in the following sections. Otherwise, it may interfere with those steps.

Check your distribution to see whether it uses the net-tools (old) or iproute2 (new) utilities. An easy test is to run this command:

whereis -b ip

If you get output such as ip: /usr/sbin/ip, then your system has the iproute2 utilities, which are preferred. Otherwise, you'll need to use net-tools.

Identifying your network interfaces

To see the overall status of your network interfaces, open a Terminal and run one of the following commands:

Using net-tools Using iproute2
ifconfig ip address show (or ip a for short)

Below are example outputs of the above commands. (All the examples on this page assume your Ethernet interface is eth0 and your Wi-Fi interface is wlan0.)

# ifconfig
eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 2c:41:38:0f:44:77  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 28  bytes 2128 (2.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 28  bytes 2128 (2.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.67.46.231  netmask 255.255.240.0  broadcast 10.67.47.255
        inet6 fe80::8ea9:82ff:fea2:c06c  prefixlen 64  scopeid 0x20<link>
        ether 8c:a9:82:a2:c0:6c  txqueuelen 1000  (Ethernet)
        RX packets 11901  bytes 14190185 (13.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6288  bytes 863161 (842.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether 2c:41:38:0f:44:77 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 8c:a9:82:a2:c0:6c brd ff:ff:ff:ff:ff:ff
    inet 10.67.46.231/20 brd 10.67.47.255 scope global dynamic wlan0
       valid_lft 1027sec preferred_lft 1027sec
    inet6 fe80::8ea9:82ff:fea2:c06c/64 scope link 
       valid_lft forever preferred_lft forever

An interface can be "up" (active) or "down" (inactive). For example, to make the eth0 interface active, run:

Using net-tools Using iproute2
ifconfig eth0 up ip link set eth0 up

Changing the MAC address

If you need to change the MAC address on an interface, use the following sequence of commands (this example changes the eth0 MAC to aa:bb:cc:11:22:33):

  • Using net-tools:
ifconfig eth0 down
ifconfig eth0 hw ether aa:bb:cc:11:22:33
ifconfig eth0 up
  • Using iproute2
ip link set eth0 down
ip link set eth0 address aa:bb:cc:11:22:33
ip link set eth0 up

Wi-Fi authentication

You can use the wpa_supplicant daemon to authenticate to a WPA, WPA2, or other type of secured network.

Create a file named wpa_supplicant.conf (this can be in any convenient directory) and open it in your favorite text editor. Below are some example configurations; feel free to tweak them as needed. Lines starting with # are comments, and wpa_supplicant skips past them.

# Configuration file for a typical WPA/WPA2 home network
ctrl_interface=/var/run/wpa_supplicant
network={
# Enter your Wi-Fi network's SSID inside the quotes
   ssid="example_name"
   scan_ssid=1
   key_mgmt=WPA-PSK
# Enter your Wi-Fi password inside the quotes
   psk="example_password"
}
# Configuration file for the "eduroam" Wi-Fi used by CSUF students and faculty
ctrl_interface=/var/run/wpa_supplicant
network={
   ssid="eduroam"
   scan_ssid=1
   key_mgmt=WPA-EAP
   pairwise=CCMP TKIP
   group=CCMP TKIP
   eap=PEAP
# Enter your email and password inside the quotes
   identity=""
   password=""
   phase1="peapver=0"
   phase2="auth=MSCHAPV2"
}

After you have saved your configuration file, point your Terminal to the same directory as the configuration file, and run the following command:

wpa_supplicant -B -i wlan0 -c wpa_supplicant.conf

If all goes well, you can now proceed to the next section.

Obtaining an IP address

If your network supports DHCP, it's easy to get an IP address. For example, to request an IP address on the wlan0 interface, run:

dhcpcd wlan0

Use ifconfig or ip a as applicable to verify that the connection is working.

You can also set a static IP, provided that it is available on your local network. For example, to set a static IP of 192.168.1.2 on the eth0 interface, run:

Using net-tools Using iproute2
ifconfig eth0 192.168.1.2 netmask 255.255.255.0 ip address add 192.168.1.2/24 dev eth0

When setting a static IP, you may need to manually add routing rules. For example:

Using net-tools Using iproute2
route add default gw 192.168.1.1 ip route add default via 192.168.1.1

More information