ip command
The ip command is the modern Linux networking utility provided by the iproute2 package. It replaces several older networking tools from the net-tools package
- OBJECT specifies what you want to manage (address, link, route, neighbor, etc.).
- COMMAND specifies the action (show, add, delete, set, flush, etc.).
| Object | Purpose |
|---|---|
addr |
IP addresses assigned to interfaces |
link |
Network interfaces (Ethernet, Wi-Fi, loopback) |
route |
Routing table |
neigh |
ARP/Neighbor cache |
rule |
Policy routing rules |
monitor |
Watch networking changes in real time |
netns |
Network namespaces |
tunnel |
GRE, IPIP, VXLAN, and other tunnels |
| Command | Description |
|---|---|
show |
Display information |
add |
Create or add an object |
del |
Delete an object |
set |
Modify an existing object |
replace |
Add or replace an existing object |
flush |
Remove all matching entries |
get |
Query information (for example, the route to a destination) |
Demo
10 most useful command
- ip addr show
- ip addr add
- ip addr del
- ip route show
- ip route add
- ip route del
- ip neigh
- ss -natp
- ss -naup
- ip link set
ip addr show
| full object and command | |
|---|---|
| brief address view with color | |
|---|---|
ip addr add
ip addr add adds an IP address to a network interface.
Basic form:
Meaning:
<ip>/<prefix>is the IP address and subnet sizedev <interface>selects the network interface- the command changes the running network configuration
Example:
This adds the address 192.0.2.10 with subnet mask 255.255.255.0 to eth0.
Check it:
ip addr del
This change is temporary. It is lost after reboot or network service restart unless you also add it to the system network configuration.
ip route show
ip route show displays the kernel routing table.
The routing table tells Linux where to send packets.
Short form:
Example output:
Meaning:
default via 192.168.1.1 dev wlan0: traffic to unknown networks goes through gateway192.168.1.1192.168.1.0/24 dev wlan0: local LAN traffic goes directly throughwlan0src 192.168.1.20: source IP used by this machine on that route
Show the route Linux will use for one destination:
ip route add
ip route add adds a route to a network.
Basic form:
Example:
This means:
- packets to
10.10.0.0/16 - should be sent to gateway
192.168.1.1 - through interface
wlan0
Add a direct route without a gateway:
Use this when the target network is directly connected to eth0.
ip route add default
The default route is the route used when no more specific route matches.
It is usually the route to the internet through your router.
Long form:
Equivalent form:
Meaning:
defaultmeans all destinations not matched by another routevia 192.168.1.1is the next-hop routerdev wlan0is the outgoing interface
Check it:
ip route del
ip route del removes a route.
Delete a network route:
Delete a direct route:
Delete the default route:
Often this shorter command is enough:
Route changes made with ip route add and ip route del are temporary. They
are lost after reboot or network service restart unless saved in the system
network configuration.
ip neigh
ip neigh shows and manages the neighbor table.
For IPv4, this is the ARP table. It maps an IP address to a MAC address on the local network.
Show neighbor entries:
Show entries for one interface:
Example output:
Common states:
REACHABLE: recently confirmed workingSTALE: known, but not recently confirmedFAILED: resolution failedPERMANENT: manually configured static entry
ip neigh add
Add a static ARP entry:
Meaning:
192.168.1.50is the IP addresslladdr aa:bb:cc:dd:ee:ffis the MAC addressdev eth0selects the interfacenud permanentmakes it a static neighbor entry
Check it:
net-tools mapping
| Legacy Tool | Modern Replacement |
|---|---|
ifconfig |
ip addr, ip link |
route |
ip route |
arp |
ip neigh |
netstat (routing) |
ip route |
netstat (sockets) |
ss |