Linux Ip Command Examples
Linux Ip Command Examples
ip OBJECT COMMAND
ip [options] OBJECT COMMAND
ip OBJECT help
ip OBJECT help
ip OBJECT h
ip a help
ip r help
Warning: The commands described below must be executed with care. If you make a mistake, you will lose connectivity to the server. You must
take special care while working over the ssh based remote session.
ip command examples
Don’t be intimidated by ip command syntax. Let us get started quickly with examples.
ip a
OR
ip addr
Sample outputs:
ip -4 a
ip -6 a
ip a show eth0
ip a list eth0
ip link ls up
OR
It is possible to use the special symbols such as + and - instead of the broadcast address by setting/resetting the host bits of the interface prex.
In this example, add the address 192.168.1.50 with netmask 255.255.255.0 (/24) with standard broadcast and label “eth0Home” to the interface
eth0:
ip addr add 192.168.1.50/24 brd + dev eth0 label eth0Home
ip -s -s a f to 192.168.2.0/24
Sample outputs:
In this example, change the default txqueuelen from 1000 to 10000 for the eth0:
Sample outputs:
ip n show
ip neigh show
The last field show the the state of the “neighbour unreachability detection” machine for this entry:
1. STALE – The neighbour is valid, but is probably already unreachable, so the kernel will try to check it at the first transmission.
2. DELAY – A packet has been sent to the stale neighbour and the kernel is waiting for confirmation.
3. REACHABLE – The neighbour is valid and apparently reachable.
In this example, add a permanent ARP entry for the neighbour 192.168.1.5 on the device eth0:
Where,
neighbou meaning
r state
(nud)
permane The neighbour entry is valid forever and can be only be removed
nt administratively
The neighbour entry is valid. No attempts to validate this entry will be made
noarp
but it can be removed when its lifetime expires.
The neighbour entry is valid but suspicious. This option to ip neigh does
stale not change the neighbour state if it was valid and the address is not
changed by this command.
reachab
The neighbour entry is valid until the reachability timeout expires.
le
Change are state to reachable for the neighbour 192.168.1.100 on the device eth1
ip -s -s n f {IPAddress}
ip -s -s n f 192.168.1.5
OR
ip -s -s n flush 192.168.1.5
ip r
ip r list
ip route list
Sample outputs:
ip r list 192.168.1.0/24
Sample outputs:
To route all traffic via 192.168.1.254 gateway connected via eth0 network interface:
Delete a route
The syntax is as follows to delete default gateway:
ip -c route
ip -c link
# The 'always' is default and color output is enabled regardless of stdout state
ip -c=always command1
ip -c=auto command2
ip -c=never command3
Please note that this flag is ignored if -json option passsed to the ip command. We can create a permanent Bash alias on Linux using the alias
command:
# run it #
ipc route
ip link
\ip route
command ip link