Progress pill
IPv4 addressing

How do I configure the network with `ip`?

IP networks - From Theory to Practice

How do I configure the network with `ip`?

  • Standard configuration
  • Activation scripts: ifup / ifdown
  • Advanced configuration: bonding

Standard configuration

After covering the theoretical foundations of networking and understanding how IP addresses, masks, routing, and translation work together, it's time to move on to practical configuration. On GNU/Linux, network setup is now handled with the ip command (iproute2 package), which replaces the older ifconfig.
ip lets you assign or change an IP address, change a mask, start or stop an interface, or check its status at any time.
TIPS: to display all interfaces (active or not): ip addr show
Example: assigning a static address and activating Interface
Add address 192.168.1.2/24 to Interface eth0:
ip addr add 192.168.1.2/24 dev eth0
Activate Interface:
ip link set dev eth0 up
Deactivate the same Interface:
ip link set dev eth0 down
Display the status of a specific Interface:
ip addr show dev eth2
Practical tip: with ip, adding an additional address to an interface no longer requires a :1 suffix. Just add another ip addr add ... line:
ip addr add 172.18.2.39/24 dev eth2

Activation scripts: ifup / ifdown

The ifup and ifdown utilities read static configuration files from /etc/sysconfig/network-scripts/ (on RHEL, CentOS, Rocky Linux, AlmaLinux...) or /etc/network/interfaces (on Debian/Ubuntu) to cleanly bring interfaces up or down.
ifup eth1 ifdown eth2
Configuration files (RHEL-like):
  • /etc/sysconfig/network: global settings (NETWORKING, HOSTNAME, GATEWAY...).
  • ifcfg-: settings specific to each interface.
Static example (ifcfg-eth0):
DEVICE=eth0 BOOTPROTO=none ONBOOT=yes IPADDR=192.168.2.5 NETMASK=255.255.255.0 GATEWAY=192.168.2.1
DHCP example:
DEVICE=eth0 BOOTPROTO=dhcp ONBOOT=yes
This modular structure is still valid and can be easily automated on current systems.

Advanced configuration: bonding

In professional environments, the aim is to guarantee service continuity and/or to aggregate bandwidth. Bonding (or teaming with teamd) mechanisms meet these needs: several physical interfaces function as a single logical Interface, often called bond0 or team0.
Prerequisites:
  • Load the bonding module (or use teamd) ;
  • Have at least two physical interfaces available.

The various common bonding methods:

ModeNamePrinciple
0balance-rrRound-robin, cyclic distribution of frames
1active-backupSingle active interface with hot failover
2balance-xorSelection based on XOR of src/dst MAC addresses
3broadcastBroadcast simultaneously on all interfaces
4802.3ad (LACP)Standardized dynamic aggregation; requires compatible switch
5tlb (Transmit Load Balancing)Balancing based on transmit load
6alb (Adaptive Load Balancing)Adaptive balancing; also balances receive via ARP

Setting up with `ip link

  • Disable physical interfaces:
ip link set eth0 down ip link set eth1 down
  • Creat the bonded Interface:
ip link add bond0 type bond mode balance-alb
  • Configure options after creation
ip link set bond0 type bond miimon 100
  • Assign MAC and IP addresses:
ip link set dev bond0 address 00:17:56:BC:02:3A ip addr add 192.168.2.3/24 dev bond0 ip route add default via 192.168.2.1
  • Attach slave interfaces:
ip link set eth0 master bond0 ip link set eth1 master bond0
  • Bring everything back up:
ip link set bond0 up ip link set eth0 up ip link set eth1 up
Tip: to detach a slave without taking down the bond: ip link set eth1 nomaster

Permanent configuration (RHEL-like)

Create three files in /etc/sysconfig/network-scripts:
ifcfg-bond0
DEVICE=bond0 ONBOOT=yes BOOTPROTO=none IPADDR=192.168.2.3 NETMASK=255.255.255.0 BROADCAST=192.168.2.255 GATEWAY=192.168.2.1 BONDING_OPTS="mode=balance-alb miimon=100"
ifcfg-eth0
DEVICE=eth0 ONBOOT=yes MASTER=bond0 SLAVE=yes
ifcfg-eth1
DEVICE=eth1 ONBOOT=yes MASTER=bond0 SLAVE=yes
Then:
systemctl restart network

Additional IP address (modern alias)

With ip, you can simply add a second address to the same device:
ip addr add 192.168.1.2/24 dev eth0
To make this alias persistent after a reboot, either add a second IPADDR2=... / PREFIX2=... block to ifcfg-eth0, or create a new NetworkManager connection via nmcli.
Thanks to ip and related commands (ip link, ip addr, ip route), network configuration is more consistent, scriptable and clear. Bonding is a key component of high-availability architectures, and assigning multiple addresses to a single interface has become much simpler.
In the next chapter, we’ll look at the specifics and implementation of IPv6 addressing.
Quiz
Quiz1/5
Which command can be used to add a static IP address to an interface on Linux?