2024-04-13
ip Command StructureThe ip command follows a consistent structure:
ip [OBJECT] [COMMAND] [OPTIONS]Where:
addr, link, route, neigh).add, del, show, set).ip linkThe ip link subcommand focuses on managing network interfaces themselves. Let’s look at some key functionalities:
1. Listing Interfaces: The simplest use is to list all available interfaces:
ip link showThis command displays detailed information about each interface, including its name, state, MAC address, and more.
2. Setting Interface Up/Down:
To bring an interface online:
ip link set dev eth0 upTo take an interface offline:
ip link set dev eth0 downReplace eth0 with the actual name of your interface.
3. Setting Interface Name:
Renaming an interface (requires root privileges):
ip link set dev eth0 name eth1Caution: Renaming interfaces can disrupt network connectivity if not done carefully.
ip addrThe ip addr subcommand is used for managing IP addresses assigned to interfaces.
1. Showing IP Addresses:
Displaying IP addresses assigned to all interfaces:
ip addr showShowing IP addresses for a specific interface:
ip addr show dev eth02. Adding an IP Address:
Adding a static IPv4 address to eth0:
ip addr add 192.168.1.100/24 dev eth0Adding a static IPv6 address to eth0:
ip addr add 2001:db8:1::100/64 dev eth03. Deleting an IP Address:
Removing an IP address from eth0:
ip addr del 192.168.1.100/24 dev eth0ip routeThe ip route subcommand allows manipulation of the routing tables.
1. Showing Routing Table:
Displaying the current routing table:
ip route show2. Adding a Static Route:
Adding a route to a remote network:
ip route add 10.0.0.0/8 via 192.168.1.1 dev eth0This adds a route to the 10.0.0.0/8 network via the gateway 192.168.1.1 on the eth0 interface.
3. Deleting a Static Route:
Removing a route:
ip route del 10.0.0.0/8 via 192.168.1.1 dev eth0ip neighThe ip neigh subcommand manages neighbor discovery entries for protocols like ARP and NDP.
1. Showing Neighbors:
Displaying neighboring hosts:
ip neigh show2. Adding a Neighbor Entry (Static ARP):
Adding a static ARP entry (for IPv4):
ip neigh add 192.168.1.101 lladdr xx:xx:xx:xx:xx:xx dev eth0Replace xx:xx:xx:xx:xx:xx with the MAC address of the host.
This adds a static entry associating the IP address 192.168.1.101 with the specified MAC address on interface eth0. This is generally not recommended unless absolutely necessary, as it can interfere with ARP resolution.
This is a detailed overview of the core functionality of the ip command. There are many more advanced options and subcommands available; exploring the man ip page will provide a detailed understanding of its full potential. Remember to always use sudo or su when performing operations that require root privileges.