Networking by CLI

(re) Naming network interface

You must load the appropriate driver to see the network interface. The existing network adapter will not have an interface without a driver. There are many virtual interfaces without hardware behind.

List existing interfaces.

# cat /proc/net/dev
# ip link
# ifconfig -a
# nmcli device status
# wicked show all
# ip -d link show ETHNAME

On-line rename interface

Bring indterface down, otherwice renaming will fail because of busy device. Then:

# ip link set eth0 down
# ip link set eth0 name dmz

Permanent rename

Modern trend to name interfaces is based on their hardware position. The history starts from using biosdevname package, then goes deep into systemd/udev. Some distros remain ethX scheme on VM if detected.

You can nail more self-describing interface name to specific NIC using /etc/udev/rules.d/70-persistent-net.rules file with similar content (Replace XX-es with factory MAC address of target NIC):

SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="XX:XX:XX:XX:XX:XX",ATTR{type}=="1",KERNEL=="eth*",NAME="dmz"

Plain ethernet

Turning interface ON without assigning IP address.

It is usefull for sniffing without IP address knowledge, for checking connected switch port, for checking negotiated speed.

# ip link set eth0 up

Same, but using ifconfig:

# ifconfig eth0 0 up

Checking link status, capabilities and negotiated speed:

# ethtool eth0
..
Link detected: yes

It is possible now to understad connected network, analyzing ARP and broadcasst requests:

# tcpdump -n -v -i eth0

Setting other MAC address

Usually, you do not need this.

Bring interface link up as described before, then change MAC address:

# ip link set eth0 00:cc:00:ff:ff:ee
 - OR -
# ifconfig eth0 hw ether 00:cc:00:ff:ff:ee

Setting ipv4 IP address

# ip addr add 192.168.1.2/24 dev eth0
 - OR -
# ifconfig eth0 192.168.1.2 netmask 255.255.255.0 up

Now you can check connection, pinging IP address in same subnet, a gateway is best choise to ping.

Wifi connection

This chapter left blank due to lack of tests, however some usefull commands:

# iw
# iwconfig
# nmcli device wifi

Bonding or link aggregation

If you plan mix VLAN and bonding technology, make bonding first, then split it into VLAN interfaces. Making bonding from VLAN interfaces will not work. Bonding makes deal with physical interfaces.

Load bonding driver, add bonding interface and check it empty

# modprobe bonding
# ip link add bond0 type bond mode active-backup # other options...
# cat /proc/net/bonding/bond0

Add interfaces to bonding interface

# ip link set dev bond0 up
# ifenslave bond0 eth0
 - OR -
# ip link set eth0 master bond0

Switching bonding active interface

Usefull for network debugging:

# ifenslave -c bond0 eth1 # Make eth1 _current_ of bond0 bonding interface

Setting IP address of bonding interface

You should no set IP address for slave interfaces, IP address belongs to bond. Set is as usual:

# ifconfig bond0 192.168.1.2 netmask 255.255.255.0 up

Bridge

Bridge is like software hub where you plug into all desired physical and virtual interfaces. Wifi interfaces are known makes problem when bridging, but may work well.

Create bridge interface

# ip link add br0 type bridge
 - OR -
# brctl addbr br0

Adding interface to bridge

# brctl addif br0 eth0
 - OR -
# ip link set eth0 master br0

Setting IP address

It does not nessecary to set up IP address on bridge interface if host does not suppose to participate in traffic. But if host should have an IP from this subnet, please assign IP address to bridge itself instead of participating interface.

VLAN interface

Before using VLANs in Linux, be sure that connected physical (or virtual) port actually transfer VLANs. This should be explicitive configured either in switch, or hypervisor configuration.

Creating VLAN interface

Suggesting that eth0 connected to trunk including VLAN with id 5:

# ip link add link eth0 name V5 type vlan id 5
# ip addr add 192.168.1.2/24 dev V5

Same, using nmcli, all configuration together:

# nmcli connection add con-name V5 type vlan id 5 ifname V5 dev eth0 ipv4.method manual ipv4.addresses 192.168.1.2/24 ipv6.method ignore

Routing

Once you have ping to your default gateway IP, belongs to same subnet you are, you can add it:

# ip route add default via GATEWAY-IP
 - OR -
# route add default gw GATEWAY-IP

# route
# ip route
# netstat -rn

Detecting MTU

Network guy said that JUMBO frames enabled in all path. Then set correct MTU on Linux:

# ifconfig eth0 mtu 9000
 - OR -
# ip link set mtu 9000 dev eth0

Now test with ping. -s defines packet load size (IP headers will add +28 bit), -Mdo set flag "do not fragment" that cause drops packet that not fits in MTU:

# ping -Mdo -s 1472 192.168.200.1
PING 192.168.200.1 (192.168.200.1) 1472(1500) bytes of data.
1480 bytes from 192.168.200.1: icmp_seq=1 ttl=63 time=5.10 ms

Bolded 1500 in output shows final packet size going out.

# ping -Mdo -s 8972 192.168.200.1
PING 192.168.200.1 (192.168.200.1) 8972(9000) bytes of data.
From 192.168.122.1 icmp_seq=1 Frag needed and DF set (mtu = 1500)
ping: local error: Message too long, mtu=1500

If this was helpfull, please donate
Updated on Wed Apr 12 12:30:54 IDT 2017 by Oleg Volkov More documentations here