Some Linux distributions use a system called iproute2 to configure network interfaces, which is a more limited version of the standard Unix system based around ifconfig. The original Linux rewrite of ifconfig was less capable, so rather than bringing it up to Unix standards it was thrown out and a new one written. This lists common tasks that are possible of both, and their equivalents. NB. “eth0” is any network interface in the format your system uses.
| Task | Unix standard | Linux iproute2 |
|---|---|---|
| List all interfaces | ifconfig | ip addr |
| List specific interface | ifconfig eth0 | ip addr show dev eth0 |
| Bring up/down interface | ifconfig eht0 up (or down) | ip link set eth0 up (or down) |
| Set IP address | ifconfig eth0 192.168.1.10/24 | ip addr add 192.168.1.10/24 dev eth0 |
| Configure using DHCP | dhclient eth0 | dhclient eth0 |
| Set IPv6 address (syntax works with add/delete/alias etc) | ifconfig eth0 inet6 2001:db8::1 prefixlen 64or | ip -6 addr add 2001:db8::1/64 dev eth0 |
| Add appletalk address | ifconfig eth0 atalk 45.156 | ip |
| Set IP + netmask + broadcast (where defaults not suitable) | ifconfig eth0 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255 | ip addr add 192.168.1.10/24 broadcast 192.168.1.255 dev eth0 |
| Add alias (not explicit on Linux) | ifconfig eth0 alias 192.168.1.2 netmask 255.255.255.0 | ip addr add 192.168.1.2/24 dev eth0 |
| Delete specific IP (not possible on old Linux) | ifconfig eth0 delete 192.168.1.2 | ip addr del 192.168.1.2/24 dev eth0 |
| Show routing table | netstat -rn | ip route |
| Add default route | route add default 192.168.1.1 | ip route add default via 192.168.1.1 |
| Delete default route | route delete default 192.168.1.1 | ip route del default via 192.168.1.1 |
| Show DNS servers | cat /etc/resolv.conf | resolvectl status |
| Add DNS server | Edit /etc/resolv.conf: | resolvectl dns eth0 8.8.8.8 |
| Delete all DNS servers | Edit /etc/resolv.conf | resolvectl dns eth0 "" |
| Set domain search order | Edit /etc/resolv.conf:search example.com local.example.com | resolvectl domain eth0 example.com local.example.com |
| Show listening sockets | netstat -an | ss -tulnp |
| Show interface statis | netstat -i | ip -s link |
| Set mtu | ifconfig eth0 mtu 9000 | ip link set dev eth0 mtu 9000 |
| View ARP cache | arp -a | ip neigh show |
Notes
Old Linux ifconfig couldn’t remove a specific IP address but could remove them all using ifconfig eth0 0.0.0.0. You can get the same effect on iproute2 using “ip addr flush dev eth0”. Unix doesn’t have a command that’s quite so destructive.
If you add an alias address on the same subnet as an existing IP address, give it a netmask of /32.
Old Linux produced a routing table using route -n (not -rn) and you’d need to use “gw” when adding or deleting one (e.g. route add default gw 192.168.1.1)
On Solaris you need to add a -p between “route” and “add” – e.g. route -p add default 192.168.1.1
Most versions of ifconfig on Unix systems accept CIDR notation as an alternative to specifying “netmask 255.255.255.255” – for example “192.168.1.1/24“
The ip command will usually infer which are IPv4 and IPv6 addresses but it can be made explicit using “ip -4” or “ip -6”. Likewise ifconfig normally doesn’t require “inet” or “inet6” to figure out which kind of IP address you’re giving it. -6 and inet6 have been used above to be 100% explicit. Linux supports fewer interface types than Unix.
It is not possible to delete or edit a single DNS server using the linux ip system, but you can delete them all and add back the ones you want.
On Linux, ip can only configure interfaces for IPv4 and IPv6 (i.e. it won’t support AppleTalk, ATM, Token Ring, or IPX etc.).
Making changes persist through boot
To configure an interface on boot on BSD use sysrc ifconfig_eth0="DHCP", for a DHCP address or edit rc.conf similarly. For a static address use ifconfig_bge0="192.168.1.123/24” and defaultrouter=”192.168.1.1” and add the nameservers to /etc/resolv.conf with a line like “nameserver 192.168.1.2” For Linux it’s much more complicated using other files or databases.
Debian/Ubuntu older versions
edit /etc/network/interfaces:
auto eth0
iface eth0 inet dhcp
For static address use:
auto eth0
iface eth0 inet static
address 192.168.1.123/24
gateway 192.168.1.1
dns-nameservers 192.168.1.2 192.168.1.3
Ubuntu with Netplan
edit /etc/netplan/01-netcfg.yaml (or similar):
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: true
For static address use:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: false
addresses: [192.168.1.123/24]
gateway4: 192.168.1.1
nameservers:
addresses: [192.168.1.2, 192.168.1.3]
Red Hat/CentOS/Fedora (using network-scripts, older versions):
Edit /etc/sysconfig/network-scripts/ifcfg-eth0:
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
For static address use:
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.123
PREFIX=24
GATEWAY=192.168.1.1
DNS1=192.168.1.2
DNS2=192.168.1.3
Systems with NetworkManager
(e.g., Fedora, Ubuntu desktop), try ip first but if you have to, use nmcli:
sudo nmcli con mod "Wired connection 1" ipv4.method auto
sudo nmcli con up "Wired connection 1"
For static address use:
sudo nmcli con mod "Wired connection 1" ipv4.method manual ipv4.addresses 192.168.1.123/24 ipv4.gateway 192.168.1.1 ipv4.dns "192.168.1.2 192.168.1.3"
sudo nmcli con up "Wired connection 1"
Replace “Wired connection 1” with your connection name (list with “nmcli con show”, get lots of stuff to tweak with “nmcli con show eth0”. You may also use the name of the ethernet interface when you find it.
Systems with systemd-networkd:
Create or edit /etc/systemd/network/20-wired.network:
[Match]
Name=eth0
[Network]
DHCP=yes
For static address use:
[Match]
Name=eth0
[Network]
Address=192.168.1.123/24
Gateway=192.168.1.1
DNS=192.168.1.2
DNS=192.168.1.3

