Skip to content

ip

Manipulate routing, network devices, interfaces and tunnels


Displays info about all network interfaces

ip addr

Only show TCP/IP IPv4

ip -4 a

Only show TCP/IP IPv6

ip -6 a

It is also possible to specify and list particular interface TCP/IP details

ip a show eno1
ip a list eno1
ip a show dev eno1

Only show running interfaces

ip link show up

Assigns the IP address to the interface

To assign 192.168.1.200/255.255.255.0 to eno1 enter:

ip a add 192.168.1.200/255.255.255.0 dev eno1

Remove / Delete the IP address from the interface

To delete 192.168.1.200/24 from eno1, enter

ip a del 192.168.1.200/24 dev eno1

How do I change the state of the device to UP or DOWN?

To make the state of the device eno1 down, enter

ip link set dev eno1 down

To make the state of the device eno1 up, enter

ip link set dev eno1 up

How do I change the MTU of the device?

To change the MTU of the device eno1 to 9000, enter

ip link set mtu 9000 dev eno1

Display neighbour/arp cache

Display neighbour/arp cache

ip neigh show

Add a new ARP entry

In this example, add a permanent ARP entry for the neighbour 192.168.1.2 on the device eno1

ip neigh add 192.168.1.5 lladdr 00:1a:30:38:a8:00 dev eno1 nud perm

Delete a ARP entry

ip neigh del 192.168.1.5 dev eno1

Change are state to reachable for the neighbour 192.168.1.100 on the device eno1

ip neigh chg 192.168.1.100 dev eth1 nud reachable

Show routing table

Show routing tabl

ip route list
default via 192.168.1.254 dev eth1 
192.168.1.0/24 dev eth1  proto kernel  scope link  src 192.168.1.10
  • Now run below from above to display routing

Display routing for 192.168.1.0/24

ip r list 192.168.1.0/24

Add a new route

Add a plain route to network 192.168.1.0/24 via gateway 192.168.1.254

ip route add 192.168.1.0/24 via 192.168.1.254

To route all traffic via 192.168.1.254 gateway connected via eno1 network interface:

ip route add 192.168.1.0/24 dev eno1

Delete a route

In this example, delete the route created in above example on this wiki

ip route del 192.168.1.0/24 dev eno1

Configure color output

# The always is default and color output is enabled regardless of stdout stat

ip -c=always command1

If parameter is 'auto', stdout is checked to be a terminal before enabling color output

ip -c=auto command2

If parameter is 'never', color output is disabled

ip -c=never command3

Always use colors - Add below to ~/.bashrc

alias ip='ip -c'

Displaying all Linux IP address

ip -br -c addr show
ip -br -c link show

How to spoof mac address without any third-party-tools

Simple example of spoofing the hwaddr

NIC="eno1"
ip link show $NIC
ip link set dev $NIC down
ip link set dev $NIC address XX:YY:ZZ:AA:BB:CC
ip link set dev $NIC up

Print all available mac addresses

ip link show | awk '/link\/ether/ { print $2 }'

Print all available mad addresses and interfaces they belongs to

ip -o link show | awk -F': ' '{print $2 ": " $0}' | awk '/link\/ether/ {print $1, $NF}'
ip -o link show | awk '/link\/ether/ {print $2 ": " $17}' # shorter version

Print all available mad addresses via a for-loop

for i in /sys/class/net/*; do
  printf "%s: %s\n" "$(basename "$i")" "$(cat "$i/address")"
done

Print only active mac addresses in use

ip -o link show up | awk '/link\/ether/ {print $2 ": " $17}'

Print only available ip addresses in use

ip -4 -o addr show | awk '{print $4}' | cut -d/ -f1