Use the ip route command to create an ip route manually on Linux.

Posted: March 10, 2016. At: 10:44 AM. This was 2 years ago. Post ID: 8773
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

This command will add an IP route to the router using the wlan0 wireless interface card on my laptop.

[email protected]:~$ sudo ip route add 0/0 via dev wlan0

This is part of the process of creating a network connection from your machine to a network when it is necessary to set IP addressing statically.

If the /sbin/ifconfig command will not list your network interface card, try the ip link command.

[email protected]:~$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether b8:ca:3a:c3:81:c4 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
    link/ether f4:b7:e2:c9:1b:e3 brd ff:ff:ff:ff:ff:ff
4: vmnet1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether 00:50:56:c0:00:01 brd ff:ff:ff:ff:ff:ff
5: vmnet8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether 00:50:56:c0:00:08 brd ff:ff:ff:ff:ff:ff

To set a static IP address on a network interface on Linux, do it this way. This is using a network mask of or 11111111.11111111.11111111.00000000.

[email protected]:~$ sudo /sbin/ifconfig wlan0

Now we have a statically assigned IP address on our network interface.

[email protected]:~$ sudo /sbin/ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr f4:b7:e2:c9:1b:e3  
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::f6b7:e2ff:fec9:1be3/64 Scope:Link
          RX packets:271481 errors:0 dropped:0 overruns:0 frame:0
          TX packets:181989 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:266603848 (254.2 MiB)  TX bytes:29934296 (28.5 MiB)

If Internet connectivity is required, edit the /etc/resolv.conf file and add nameservers to allow the computer to resolve domain names and access websites.

[email protected]:~$ cat /etc/resolv.conf 
# Generated by NetworkManager

The above /etc/resolv.conf file is for a home user that has a router IP address of and is wanting to use Google Domain Name Service to help resolve Internet IP addresses. I had to do this when trying to setup the Blackarch Linux distribution and it did not setup an Internet connection automatically. It was necessary to do this manually.

No comments have been made. Use this form to start the conversation :)

Leave a Reply