Tip of the week 42
Use the ip command under linux
As you know (or not) the ifconfig command is deprecated since many years now and not developped anymore since 2001, it's still present but for now you should use the ip command which is a part of the iproute2 package, it supports all functions of ifconfig, route, arp, netstat and many others (multicast, tunnels, etc)
Here is the ip command syntax :
~ ip help
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
ip [ -force ] -batch filename
where OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable |
tunnel | tuntap | maddr | mroute | mrule | monitor | xfrm |
netns }
OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
-f[amily] { inet | inet6 | ipx | dnet | link } |
-l[oops] { maximum-addr-flush-attempts } |
-o[neline] | -t[imestamp] | -b[atch] [filename] |
-rc[vbuf] [size]}
Few examples below :
Control the physical and logical state of an interface :
~ sudo ip link set wlan0 up
Set up an IP address (yes you can use CIDR notation):
~ ip addr add 192.168.2.1/24 dev eth0
Return the IP addresses :
~ ip addr
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
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: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether e8:03:9a:b2:a4:11 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether c4:85:08:1b:f4:04 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.25/24 brd 192.168.1.255 scope global wlan0
valid_lft forever preferred_lft forever
inet6 fe80::c685:8ff:fe1b:f404/64 scope link
valid_lft forever preferred_lft forever
Display the routing table
~ ip route
default via 192.168.1.1 dev wlan0 proto static
169.254.0.0/16 dev wlan0 scope link metric 1000
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.42.1
192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.25 metric 2
Display a routing entry for a specific subnet :
~ ip ro get 8.8.8.8
8.8.8.8 via 192.168.1.1 dev wlan0 src 192.168.1.25
cache
Show ARP entries :
~ ip neighbor
192.168.1.1 dev wlan0 lladdr 2c:39:96:2a:2f:9c REACHABLE
fe80::2e39:96ff:fe2a:2f9c dev wlan0 lladdr 2c:39:96:2a:2f:9c router DELAY
Show link statistics :
~ ip -s 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
RX: bytes packets errors dropped overrun mcast
54244 563 0 0 0 0
TX: bytes packets errors dropped carrier collsns
54244 563 0 0 0 0
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether e8:03:9a:b2:a4:11 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
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether c4:85:08:1b:f4:04 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
5185017 6229 0 0 0 0
TX: bytes packets errors dropped carrier collsns
1178874 4200 0 0 0 0
Comments