Master Linux Network Configuration: IP, Routing, Bonding and More
This guide walks through Linux network fundamentals, covering hostname, IP address, netmask, gateway, DNS, interface status, routing tables, and tools like ifconfig, ip, route, ss, netstat, traceroute, nslookup, tcpdump, as well as temporary and permanent IP changes, interface renaming, dual‑NIC bonding, and practical command examples.
Linux Network Configuration and Basic Services
1 Configure Network Settings
Hostname: hostname
IP address/netmask: ifconfig; ip a
Default gateway: route -n
DNS server: cat /etc/resolv.conf
Network connection status: ss, netstat
Domain name resolution: nslookup, host
2 ifconfig
ifconfig specific NIC name # show detailed info for a specific NIC
ifconfig -a # show all NICs, including inactive ones
ifconfig NIC_NAME [up|down] # enable or disable a NIC
ifconfig NIC_NAME ip_address/netmask # set IP and netmask
ifconfig NIC_NAME ip_address/subnet_len # temporary change NIC name
ifconfig ens33:0 address # virtual NICifconfig modify IP address
inconfig ens33 new IP address
[root@localhost ~]# ifconfig ens33 192.168.11.8
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.11.8 netmask 255.255.255.0 broadcast 192.168.11.255
inet6 fe80::42b7:9714:f504:2343 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:96:50:48 txqueuelen 1000 (Ethernet)
RX packets 641 bytes 49417 (48.2 KiB)ifconfig add temporary IP address
ifconfig delete temporary IP address
Permanent IP address modification
# vim /etc/sysconfig/network-scripts/ifcfg-ens33
Best to restart the network service: # systemctl restart network
3 Modify Network Interface Name
Temporary rename
ip link set ens36 down
# first bring the NIC down
ip link set ens36 name abc
# then rename
ip link set abc up
# finally bring it upSteps: ① down the interface ② rename ③ up the interface
4 Permanent rename
# vim /etc/default/grub
reboot/init 6 succeeded
5 Practical: Dual‑NIC Configuration (experiment not finished)
① Add a NIC in the virtual machine
② Copy ens33 configuration to ens36
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens36
[root@localhost network-scripts]# vim ifcfg-ens36
TYPE=Ethernet
BOOTPROTO=static
NAME=ens36
DEVICE=ens36
ONBOOT=yes
IPADDR=192.168.91.110
NETMASK=255.255.255.0
GATEWAY=192.168.91.2
[root@localhost network-scripts]# systemctl restart network
[root@localhost ~]# ping 192.168.11.20
PING 192.168.11.20 (192.168.11.20) 56(84) bytes of data.
64 bytes from 192.168.11.20: icmp_seq=1 ttl=64 time=0.058 ms
64 bytes from 192.168.11.20: icmp_seq=2 ttl=64 time=0.051 ms
64 bytes from 192.168.11.20: icmp_seq=3 ttl=64 time=0.050 ms
64 bytes from 192.168.11.20: icmp_seq=4 ttl=64 time=0.049 ms
64 bytes from 192.168.11.20: icmp_seq=5 ttl=64 time=0.048 ms③ Modify ens36 configuration file
④ Test
6 IP
ip link – Data Link Layer
[root@localhost ~]# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:96:50:48 brd ff:ff:ff:ff:ff:ff
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT qlen 1000
link/ether 52:54:00:8d:7b:87 brd ff:ff:ff:ff:ff:ff
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN mode DEFAULT qlen 1000
link/ether 52:54:00:8d:7b:87 brd ff:ff:ff:ff:ff:ffip addr – Network Layer
[root@localhost ~]# ip addr
# can be shortened to ip a
[ip address add 172.19.8.211/16 dev ens33]
# add a new virtual IP
[ip address add 10.0.0.88/24 dev ens33] # temporary IP
[ip address del 10.0.0.8/24 dev ens33]ip route – Routing
[root@localhost ~]# ip route
default via 192.168.11.2 dev ens33 proto static metric 100
192.168.11.0/24 dev ens33 proto kernel scope link src 192.168.11.20 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1route -n
7 Add/Delete Routes
Route fields meaning
Destination, Gateway, Genmask, Flags, Metric, Ref, Use, Iface
① route add -net 10.0.0.0/8 gw 192.168.227.2
Temporarily add a route to the 10.0.0.0 network via the specified gateway.
② route del -net 10.0.0.0/8
Delete the route to the 10.0.0.0 network.
③ route add -net 0.0.0.0 (default) gw 192.168.227.2
Add a default route.
④ Permanent route addition
# vim /etc/sysconfig/network-scripts/route-ens33
10.0.0.0/24 via 192.168.11.11
# systemctl restart network8 ss / netstat – Network Connection Status
Service not working, ftp/httpd cannot be accessed
1. Ping to check connectivity and firewall status
2. systemctl status <service_name> to see if the service is running
3. ss or netstat to see if ports are occupied
4. Verify service configuration filesnetstat
View network connections with options such as -a (all), -n (numeric), -t (TCP), -u (UDP), -r (routing), -l (listening), -p (process info, requires root).
ss
View network connections with options: -t (TCP), -u (UDP), -w (raw), -x (unix), -l (listening), -a (all), -n (numeric), -p (process), -e (extended), -m (memory), -o (timer), -r (resolve).
Difference
ss operates closer to the kernel and is faster; netstat is user‑level and slower.
9 traceroute – IP Path Tracing
Trace the route packets take to a destination.
10 nslookup
Domain name resolution; verifies DNS server functionality. Other tools include dig, host, ping.
11 Change Hostname
Temporary change
[root@localhost ~]# hostname mgThe change disappears after reboot.
Permanent change
① Command line
② Edit configuration file
12 tcpdump – Packet Capture
A powerful network protocol analyzer for monitoring and capturing traffic, widely used for troubleshooting, performance analysis, and security auditing.
① Capture on a specific NIC
② List available NICs
③ Capture specific host traffic
# tcpdump -i eth0
# tcpdump host 192.168.11.12
# tcpdump src host 192.168.11.12
# tcpdump dst host 192.168.11.12
# tcpdump tcp port 22 and src host 192.168.11.12
# tcpdump ip host 172.16.12.10 and 192.168.11.12
# tcpdump -i eth1 -t -s 0 -c 100 and dst port ! 22 and src net 172.16.12.0/24 -w ./target.cap
# tcpdump -c 100013 Bond Multi‑NIC Bonding
Provides redundancy (active‑backup) or load balancing (dual‑master) by binding multiple NICs to a single virtual interface.
① Add a NIC in the VM
② Switch to the configuration directory
③ Edit bond0 configuration
④ Modify ens33 and ens36
⑤ Restart network scripts
⑥ Test
# systemctl stop firewalld
setenforce 0
cd /etc/sysconfig/network-scripts
ifconfig
cp ifcfg-ens33 ifcfg-bondo
vim ifcfg-bond0
# (additional configuration steps)14 View bond0 Status
Bonding method two (rarely used)
# centos8: nmcli bonding
nmcli con add con-name static ifname eth0 autoconnect no type Ethernet ipv4.addresses 172.25.X.10/24 ipv4.gateway 172.25.X.254
nmcli connection modify ens33 ipv4.addresses 192.168.91.100/2
nmcli connection up ens33
# add bonding interface
nmcli con add type bond con-name mybond0 ifname bond0 mode active-backup ipv4.method manual ipv4.addresses 192.168.91.123/24
# add slave interfaces
nmcli con add type bond-slave ifname ens33 master bond0
nmcli con add type bond-slave ifname ens36 master bond0
# bring up slaves and bond
nmcli con up bond-slave-ens33
nmcli con up bond-slave-ens36
nmcli con up mybond0Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
