iproute2

From Gentoo Wiki
Jump to:navigation Jump to:search
This page contains changes which are not marked for translation.

iproute2 is a tool developed to unify network interface configuration, routing, and tunneling for Linux systems.

iproute2 provides the ip command for this purpose.

Installation

USE flags

USE flags for sys-apps/iproute2 kernel routing and traffic control utilities

atm Enable Asynchronous Transfer Mode protocol support
berkdb build programs that use berkdb (just arpd)
bpf Use dev-libs/libbpf
caps Use Linux capabilities library to control privilege
elf support loading eBPF programs from ELFs (e.g. LLVM's eBPF backend)
iptables include support for iptables filtering
minimal only install ip and tc programs, without eBPF support
nfs Support RPC lookups via net-libs/libtirpc in ss
selinux !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur

Emerge

sys-apps/iproute2 is part of the system set.

root #emerge --ask sys-apps/iproute2

Usage

IPv4 and IPv6 support

iproute2 supports both IP address families, IPv4 and IPv6. By default the ip command refers only to IPv4 protocol, explicit IP address family namimng for IPv4 ip -4 is also possible. IPv6 uses the ip -6 command.

Listing interfaces

Use ip link for displaying the interface link of all interfaces:

user $ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 00:22:68:13:da:7d brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:1e:65:6b:ef:ca brd ff:ff:ff:ff:ff:ff

Showing IP addressing

Either ip addr for displaying all IP information of all interfaces, or use ip address show for displaying the configuraton of a specific interface with assigned IP address:

user $ip addr show wlan0
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:1e:65:6b:ef:ca brd ff:ff:ff:ff:ff:ff
    inet 192.0.2.10/24 brd 192.0.2.255 scope global wlan0
       valid_lft forever preferred_lft forever

Activating interfaces

Interface links can be activated and deactivated (respectively) using the set subcommand:

root #ip link set wlan0 down
root #ip link set eth0 up

Showing active interfaces

Display only active network interfaces. Notice, interface wlan0 has been deactivated using previous example, and is not shown in the output:

user $ip link show up
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:22:68:13:da:7d brd ff:ff:ff:ff:ff:ff

Configuring IP addressing

Removing IP addressing from the wlan0 interface:

root #ip addr del 192.0.2.10/24 dev wlan0

Adding IP addressing to the eth0 interface:

root #ip addr add 192.0.2.11/24 dev eth0
root #ip -6 addr add 2001:db8::11/64 dev eth0

Configure IP routing

Adding IP default route for both IP address families, IPv4 and IPv6:

root #ip route add default via 192.0.2.1
root #ip -6 route add default via fe80::1

Display the IPv4 routing table information:

user $ip route
default via 192.0.2.1 dev eth0  metric 2 
127.0.0.0/8 via 127.0.0.1 dev lo 
192.0.2.0/24 dev eth0  proto kernel  scope link  src 192.0.2.11

Display the IPv6 routing table information:

user $ip -6 route
2001:db8::10/64 dev eth0  proto kernel  metric 2003  mtu 1492
fe80::/64 dev eth0  proto kernel  metric 256  pref medium
ff00::/8 dev eth0  metric 256  
default via fe80::1 dev eth0  metric 2003  mtu 1492

iproute2 for net-tools swappers

The following table can be used as a reference point for substituting commands from the sys-apps/net-tools package for the equivalent sys-apps/iproute2 commands:

net-tools to iproute2 command equivalents
net-tools iproute2
ifconfig (interface list) ip link
ifconfig (ip configuration) ip addr
ifconfig (interface stats) ip -s link
route ip route
arp ip neigh
brctl addbr ip link add ... type bridge
brctl addif ip link set master
netstat ss
netstat -g ip maddr
netstat -i ip -s link
netstat -r ip route
iptunnel ip tunnel
ipmaddr ip maddr
tunctl ip tuntap[1]
(none) for interface rename ip link set dev OLDNAME name NEWNAME
brctl bridge[2]

See also

  • Static routing — covers routing of the IP protocol in the Linux kernel.

External resources

References

  1. Since iproute-2.6.34
  2. Since iproute-3.5.0