shell怎么获取ip地址各数值

2023-04-11 03:47:00 获取 地址 数值
shell获取ip地址各数值 1. ifconfig 使用ifconfig命令可以查看本机ip地址,如下所示: [root@localhost ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:6F:8D:58 inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe6f:8d58/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:950 errors:0 dropped:0 overruns:0 frame:0 TX packets:781 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:106960 (104.4 KiB) TX bytes:114960 (112.0 KiB) Interrupt:16 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:26 errors:0 dropped:0 overruns:0 frame:0 TX packets:26 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1960 (1.9 KiB) TX bytes:1960 (1.9 KiB) 2. netstat 使用netstat命令可以查看ip地址、接口状态等信息,如下所示: [root@localhost ~]# netstat -an|grep ":80" tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN tcp 0 0 :::80 :::* LISTEN 3. ip 使用ip命令可以查看更多网络信息,如下所示: [root@localhost ~]# ip addr 1: lo: mtu 16436 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 inet6 ::1/128 scope host 2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:6f:8d:58 brd ff:ff:ff:ff:ff:ff inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0 inet6 fe80::20c:29ff:fe6f:8d58/64 scope link 4. /etc/sysconfig/network-scripts/ifcfg-eth0 使用vim编辑器编辑/etc/sysconfig/network-scripts/ifcfg-eth0文件,可以查看ip地址、子网掩码、网关等信息,如下所示: DEVICE=eth0 HWADDR=00:0C:29:6F:8D:58 TYPE=Ethernet UUID=e90175e3-8d48-4aae-aebb-0a3c7a90a1b1 ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static IPADDR=192.168.1.100 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS1=192.168.1.1 以上就是shell获取ip地址各数值的方法。

相关文章