- Linux Administration Cookbook
- Adam K. Dean
- 367字
- 2021-07-02 14:24:27
Discerning the IP (deprecated method)
On older systems, or those managed by stick-in-the-mud admins, you might also use ifconfig to find the IP and subnet.
Simply running ifconfig will print all relevant information:
$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::5054:ff:fec9:c704 prefixlen 64 scopeid 0x20<link>
ether 52:54:00:c9:c7:04 txqueuelen 1000 (Ethernet)
RX packets 14404 bytes 12885029 (12.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5672 bytes 409079 (399.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.33.10 netmask 255.255.255.0 broadcast 192.168.33.255
inet6 fe80::a00:27ff:fe4b:3de prefixlen 64 scopeid 0x20<link>
ether 08:00:27:4b:03:de txqueuelen 1000 (Ethernet)
RX packets 8 bytes 3164 (3.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 17 bytes 1906 (1.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 08:00:27:50:a5:cb txqueuelen 1000 (Ethernet)
RX packets 43 bytes 14706 (14.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 112 bytes 19336 (18.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
As with IP, it's trivial to dump the information about a specific interface.
As we can see in the following code, we're looking again at the specifics of eth1:
$ ifconfig eth1
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.33.10 netmask 255.255.255.0 broadcast 192.168.33.255
inet6 fe80::a00:27ff:fe0d:d90c prefixlen 64 scopeid 0x20<link>
ether 08:00:27:0d:d9:0c txqueuelen 1000 (Ethernet)
RX packets 24 bytes 4268 (4.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 20 bytes 2116 (2.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
I use the word deprecated for this, but that's generally only true for the Linux world. In the BSDs and macOS, ifconfig is still very much the only show in town, and it's still being actively improved and maintained.