For more than 20 years, I've used the ifconfig
to manage network cards and network connections on my computers. The ip
command has been around several years: it's past due for me to learn to use it. A couple recent pushes: Debian 9 seems to remove the ifconfig
command entirely, and I found that Packt's rather good DevOps Automation Cookbook (Michael Duffy, 2015) has a very good introduction. From which this is mostly copied.
$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether bb:88:f3:78:3a:ca brd ff:ff:ff:ff:ff:ff
inet 192.168.0.104/24 brd 10.0.0.255 scope global dynamic enp2s0
valid_lft 42730sec preferred_lft 42730sec
inet6 fce7:fca7:79b7::ea6/128 scope global
valid_lft forever preferred_lft forever
inet6 fce7:fca7:79b7:0:72d4:5e48:294f:20e5/64 scope global noprefixroute dynamic
valid_lft 6795sec preferred_lft 1395sec
inet6 fd80::8fa0:1c8d:925f:7f3a/64 scope link
valid_lft forever preferred_lft forever
3: wlp3s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether 32:61:e1:3c:d1:f4 brd ff:ff:ff:ff:ff:ff
This is an informational query and doesn't require root permissions.
You can likewise query a specific interface with ip addr show enp2s0
.
To add an address: ip addr add 192.168.0.111/24 dev enp2s0
, and it can be removed by the very similar command ip addr del 192.168.0.111/24 dev enp2s0
. These commands require root (and yes, you can assign two IP addresses to the same card like that).
To put an interface up or take it down also requires root, and is just as easy (although slightly different): ip link set enp2s0 down
and ip link set enp2s0 up
.
To see interface statistics:
$ ip -s link
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
RX: bytes packets errors dropped overrun mcast
103294451 218144 0 0 0 0
TX: bytes packets errors dropped carrier collsns
103294451 218144 0 0 0 0
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether bb:88:f3:78:3a:ca brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
11535994858 8190736 0 0 0 5307
TX: bytes packets errors dropped carrier collsns
344123406 3541344 0 3 0 0
3: wlp3s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DORMANT group default qlen 1000
link/ether 32:61:e1:3c:d1:f4 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0
Again, this is information (not a setup change) and doesn't require root access. To get further statistics on a single interface, use ip -s link ls enp2s0
... I personally find the use of ls in here non-obvious as the behaviour doesn't match that in the commands I've already covered where just adding the interface name would appear to be enough. For more stats, use ip -s -s link ls enp2s0
(note that -ss doesn't appear to work).