IP Command Guide
The ip command is a powerful utility in Linux for managing network interfaces, IP addresses, routing tables, and ARP cache. It's a modern replacement for older tools like ifconfig and route.
Network Interface Management with ip addr
To display all network interfaces and their associated IP addresses, use the ip addr command. This is fundamental for understanding your system's network configuration.
# To display all interfaces with addresses:
ip addr
You can also manage the state of network interfaces. For instance, to bring a wireless adapter up or down:
# To take down / up the wireless adapter:
ip link set dev wlan0 {up|down}
Configuring a static IP address is a common task. Here's how to add a specific IP address and netmask to an interface:
# To set a static IP and netmask:
ip addr add 192.168.1.100/32 dev eth0
To remove an IP address or flush all IPs from an interface:
# To remove a IP from an interface:
ip addr del 192.168.1.100/32 dev eth0
# To remove all IPs from an interface:
ip address flush dev eth0
Routing Table Configuration with ip route
The ip route command is used to view and manipulate the kernel routing table. This is crucial for directing network traffic.
# To display all routes:
ip route
# To display all routes for IPv6:
ip -6 route
Adding a default route to specify the gateway for all outgoing traffic:
# To add default route via gateway IP:
ip route add default via 192.168.1.1
You can also add specific routes for particular network destinations:
# To add route via interface:
ip route add 192.168.0.0/24 dev eth0
To determine which route would be used for a specific destination IP:
# To get the route used for an destination
ip route get to 8.8.8.8
MAC Address Manipulation with ip link
The ip link command allows you to modify network device properties, including the MAC address.
# To change your mac address :
ip link set dev eth0 address aa:bb:cc:dd:ee:ff
Neighbor Cache Management
View the neighbor cache, which stores mappings between IP addresses and MAC addresses (ARP for IPv4, NDP for IPv6).
# To view neighbors (using ARP and NDP):
ip neighbor show
Understanding and utilizing the ip command is essential for any system administrator or developer working with Linux networking. For more advanced configurations and options, consult the official documentation.