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 192.168.5.5/24 dev eth0
ip link set dev eth0 up
or
ifconfig eth0 192.168.5.5/24 up
or
ifconfig eth0 192.168.5.5 netmask 255.255.255.0 up
Deleting the interface configuration:
ifconfig eth0 0.0.0.0 down
or
ip addr del 192.168.5.5/24 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 192.168.6.5/24 up
VLANs
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.
Bonding
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
Configuration:
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 192.168.5.1
or
ip route add default via 10.66.255.254
add a normal route for a subnet via a router:
route add -net 192.168.6.0/24 gw 192.168.5.1
or
ip route add to 192.168.6.0/24 via 192.168.5.1
Delete routes:
Del a default route:
route del default
Delete a network route:
route del -net 192.168.6.0/24
or
ip route del to 192.168.6.0/24
© Guido Socher,