Recently, I need to configure a bunch of switches to construct a leaf-spine network. And IP command is a good choice to do this software-base configuration. And how I summaried the ip command’s usage bases on the document which is written by Alexey N. Kuznetsov.
Use who
command to list the users logining the same machine currently.
Use service network restart
or /etc/init.d/networking restart
to restart the network module in Linux.
1. Overview
IP command which is a utility from iproute2 package is used to configure the Linux network.
The ip command syntax:
ip [options] object [command [arguments]]
Options( a set of optional modifiers affecting the general behaviour of the ip utility or changing its output ):
- -V/Version
- -s/statistics: use one time to output more information. use twice time to output more information.
- -o/oneline: output record on a single line
Objects( the object to manage or to get information about ):
- link: network device
- address: IP or IPv6 address
- neighbour: ARP or NDISC(Neighbor Discover Protocol for ipv6) cache entry
- route: routing table entry
- rule: rule in routing policy databse
- maddress: multicast address
- mroute: multicast routing cache entry
- tunnel: tunnel over IP
Commands: add/delete/show/help
Arguments: flags and parameters
error messages
- syntax error
- argument verification
- ip compilation failure
- syscall error from kernel
2. IP Link – network device configuration
2.1 ip link set
Arguments:
- dev NAME(default)
- up/down
- arp on/off
- multicast on/off
- dynamic on/off
- name NAME
- txqueuelen/txqlen NUMBER
- mtu Number
- address LLADDRESS
- broadcast LLADDRESS
2.2 ip link show
Arguments:
- dev NAME(default)
- up: display running interfaces
2.2.1 An example of using ip link show
on Ubuntu 2018 x86_64:
1
2
3
4
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
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 fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 00:0c:29:b9:bd:c8 brd ff:ff:ff:ff:ff:ff
Explanation:
- interface index: the number before the colon
- interface name
- interface flags:
- UP: the device is turned on.
- LOOPBACK: all packets will be returned but bounced packets.
- BROADCAST: sent packets to all hosts sharing the same link.
- POINTOPOINT
- MULTICAST: a bigger type on Broacast
- mtu: maximal transfer unit
- qdisc: queuing discipline
- noqueue: the interface does not queue anything
- noop: blackhole model and discard anything
- qlen: default ransmit queue length
- link layer address and device mac address: second line’s information
2.2.2 An example of using ip -s -s link ls ens33
1
2
3
4
5
6
7
8
9
10
ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 00:0c:29:b9:bd:c8 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
596509 3028 0 0 0 0
RX errors: length crc frame fifo missed
0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
316030 2201 0 0 0 0
TX errors: aborted fifo window heartbeat transns
0 0 0 0 4
Explanation:
- RX/TX: receiver and transmitter statistics
- different type of bytes or packets
3. IP Address – protocol address management
3.1 ip address add
Arguments:
- dev NAME
- local ADDRESS(default)
- broadcast ADDRESS
Example:
ip addr add 10.0.0.1/24 brd + dev eth0 label eth0:Alias
: add the address 10.0.0.1 with prefix length 24 (i.e. netmask 255.255.255.0), standard broadcast and label eth0:Alias to the interface eth0.
3.2 ip address delete
This command coincides with the arguments of ip addr add
.
3.3 ip address show
This command shows the details of the ip address configuration.
3.4 ip address flush
dangerous, similiar to delete command
4. IP Neighbour
Neighour objects establish bindings between protocol addresses and link layer addresses for hosts sharing the same link. The IPv4 neighbour table is known as the ARP table.
- ip neigh add/change/replace
- ip neigh delete
- ip neigh show
- ip neigh flush
Example:
ip neigh add 10.0.0.3 lladdr 0:0:0:0:0:1 dev eth0 nud perm
: add a permanent ARP entry for the neighbour 10.0.0.3 on the device eth0.
5. IP Route – routing table management
Route entries in the kernel routing tables keep information about paths to other networked nodes.
All of the packets will obey the routes based on the prefix its ip address matches. If several routes match the packet, the longest matching prefix is selected.
- ip route add/change/replace
- ip route delete
- ip route show
- ip route flush
- ip route get
Example:
ip route add 10.0.0/24 via 193.233.7.65
: add a plain route to network 10.0.0/24 via gateway 193.233.7.65.
6. Other Commands
IP Rule – routing policy database management
Rules in the routing policy database control the route selection algorithm.
- ip rule add/delete
- ip rule show
IP maddress – multicast addresses management
IP mroute – multicast routing cache management
IP tunnel – tunnel configuration
Error Record:
-
When the file interfaces does not work, the problem mostly is in the interfaces file’s content which contains some mistakes or lack in some tools. Once the file interfaces does not work although I restarted the network module. The problem is that I did not install ethtool which is used in interfaces file.
Ethtool is a useful utility used for Network Interface Card configuration. It is easy toconfigure the IP address, interface speed, interface duplex or half duplex.