Linux network configuration

We have almost forgotten how to configure IP networking thanks to network manager and all kinds of distribution dependent helper scripts. Here is how to configure basic networking when you don't have all those tools. It's good for temporary configurations or when your PC is booted in rescue mode.

Print the currentnetwork configuration

ip address show or ifconfig
ifconfig prints only interfaces that are up to see all interfaces you can use:
ifconfig -a

To print routing and GW configuration:
route -n or netstat -rn or ip route show

Basic network interface configuration

ip addr add dev eth0 ip link set dev eth0 up or ifconfig eth0 up or ifconfig eth0 netmask up

Deleting the interface configuration:
ifconfig eth0 down or ip addr del dev eth0 ip link set dev eth0 down

Sub-interfaces and multiple networks on one interface

It is possible to access multiple local networks via the same physical interface by just creating a sub interface. Such a sub-interface is just a different name and endpoint for the same physical interface. You can simply put a colon after the physical interface name
ifconfig eth0:0 up


IEEE 802.1q networking can be configured in an number of ways and some of those commands such as vconfig may not work across all linux distributions. The "ip link" command should work everywhere. The following example uses vlan ID 8:
ip link add link eth0 name eth0.8 type vlan id 8
This gives you the network interface eth0.8 and you can assign an IP to it as shown further up.


Your Linux distribution may have commands like ifenslave installed to help with the configuration of a link aggregation (LAG) but the most basic way to configuring it is to directly work with bonding kernel module. This is the module responsible for link aggregation.
print bonding kernel module options: modinfo bonding view the current configuration: more /proc/net/bonding/* ip -details link show
The most common way of doing bonding is IEEE 802.3ad which uses a protocol called LACP between the switch and the server. This is bond mode 4 in Linux.
bonding config files: /sys/class/net/bonding_masters and /sys/class/net/YOUR-BOND-NAME/bonding/slaves
defining the bond: echo "+bond0" > /sys/class/net/bonding_masters configuring it and adding interfaces: echo 4 > /sys/class/net/bond0/bonding/mode echo "+eth0" > /sys/class/net/bondipmi/bonding/slaves echo "+eth1" > /sys/class/net/bondipmi/bonding/slaves

Routing and Default Gateway configuration

Note that you must have an interface where you can reach a GW before you can define a route via the GW.
Add a default route: route add default gw or ip route add default via add a normal route for a subnet via a router: route add -net gw or ip route add to via

Delete routes:
Del a default route: route del default Delete a network route: route del -net or ip route del to

© Guido Socher,