Linux Networking

Summary

Linux Networking Commands

Common commands:

ip Command to show and manipulate network devices and routing
ifconfig Deprecated command for configuring network devices
route Deprecated command for managing network routes
ifup/down Bring a network interface up or down
ss Show socket connections
netstat Deprecated command for showing network connection
arp Deprecated command for showing ARP information

ip

Configuring an IP address

# Assign an IP address to a specific interface
ip addr add 192.168.50.5 dev eth1

# Set an IP with a specific netmask
ip addr add 192.168.50.5/23 dev eth1

# Remove an IP address (best to use full CIDR)
ip addr del 192.168.50.5/23 dev eth1

# Show all interfaces
ip addr show

# Show a specific interface
ip addr show dev eth1

This replaces ifconfig.

Configuring network interfaces

# Bring an interface up
ip link set eth1 up

# Bring an interface down
ip link set eth1 down

# Set the MTU
ip link set eth1 mtu 9000

This replaces ifconfig.

Configuring the routing information

# Adding the default gateway
ip route add default via 192.168.50.1

# Add a static route
ip route add 10.20.10.0/24 via 192.168.50.1

# Remove a static route
ip route del 10.20.10.0/24

# Show route table
ip route show

This replaces route.

ARP table management

# Show ARP table
ip neigh

# Show verbose ARP table
ip -s neigh

# Add new ARP table entry
ip neigh add 192.168.50.20 lladdr 1:2:3:4:5:6 dev eth1

# Remove ARP table entry
ip neigh del 192.168.50.20 dev eth1

This replaces arp.

Showing network socket information

# Show all network stats
ss

# Show all TCP network stats without DNS lookups
ss -nt

# Show multicast addresses
ip maddr

This replaces netstat.

Networking on Red Hat

NetworkManager
The default networking daemon on CentOS 7
nmtui
A simple curses-based text user interface (TUI) for NetworkManager
nmcli
A command-line tool provided to allow users and scripts to interact with NetworkManager

Configuring networking in Red Hat

/etc/sysconfig/network-scripts
Interface specific information is stored in ifcfg files in this directory
/etc/sysconfig/network
A file that contains global network settings (i.e. VPNs, etc).

/etc/sysconfig/network-scripts/ifcfg-eth0

# Static
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
PREFIX=24
IPADDR=10.0.1.27

# DHCP
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes

Notifying NetworkManager of changes

NetworkManager needs to be made aware of the change by running:

nmcli connection reload

Or if you only want it to change the file you changed:

nmcli con load /etc/sysconfig/network-scripts/ifcfg-eth0

Bringing the interface up:

ifup eth0

# OR

nmcli con up eth0

Consistent Network Device Naming

Device Naming Hierarchy

By default, systemd uses the following policies for naming:

  1. Using Firmware or BIOS index numbers for on-board devices (i.e. eno1)
  2. Using Firmware or BIOS provided PCI Express hotplug slot index numbers (i.e. ens1)
  3. Using physical location of the connector of the hardware (i.e. enp2s0)
  4. Using interfaces MAC address (i.e. enx78e7d1ea46da)
  5. Fallback to unpredictable kernel naming scheme (i.e. eth0)

Can be disabled with net.ifnames=0 biosdevname=0 set at boot

Predictable naming formats

Two character prefixes:

en Ethernet
wl Wireless (WLAN)
ww Wireless wide network (WWAN)

Predictable naming formats

Device Name Types:

o<index>
on-board device index number
s<slot>[f<function>][d<dev_id>]
hotplug slot index number
x<MAC>
MAC address
p<bus>s<slot>[f<function>][d<dev_id>]
PCI geographical location

Example:: enP2p1s0f4

Advanced Networking

Ethernet Bonding
Bind multiple interfaces into a single bonded, channel. Channel bonding enables two or more network interfaces to act as one, simultaneously increasing the bandwidth and providing redundancy.
Networking Teaming
Newer implementation of ethernet bonding. Provides an API interface which user-space applications can use.

Advanced Networking

Network Bridges
Link-layer device which forwards traffic between networks based on MAC addresses. A software bridge can be used within a Linux host in order to emulate a hardware bridge, for example in virtualization applications for sharing a NIC with one or more virtual NICs.
VLAN tagging
Using tagged VLANs on interfaces.

Resources

Class Announcements