在Linux中有三种查看ip地址的方法,下面我分别来介绍
1.ip address命令
使用ip address命令可以查看具体是ip信息
[root@lixian ~]#ip address 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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:8b:2e:bb brd ff:ff:ff:ff:ff:ff inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::345d:38a5:8df5:e4e9/64 scope link noprefixroute valid_lft forever preferred_lft forever [root@lixian ~]#
ip adderss可以简写成 ip a
查看具体的指定网卡详细信息
[root@lixian ~]#ip address show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:8b:2e:bb brd ff:ff:ff:ff:ff:ff inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::345d:38a5:8df5:e4e9/64 scope link noprefixroute valid_lft forever preferred_lft forever [root@lixian ~]#
ip address show eth0可以简写成ip a s eth0
2.ifconfig命令
使用ifconfig需要yum安装net-tools软件
[root@lixian ~]#yum -y install bash-completion Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.cn99.com * extras: mirrors.163.com * updates: mirrors.163.com base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package bash-completion.noarch 1:2.1-6.el7 will be installed ..................此处省略部分输出内容..................... Transaction test succeeded Running transaction Installing : 1:bash-completion-2.1-6.el7.noarch 1/1 Verifying : 1:bash-completion-2.1-6.el7.noarch 1/1 Installed: bash-completion.noarch 1:2.1-6.el7 Complete!
ifconfig eth0 可以指定某个网卡查看详细信息
[root@lixian ~]#ifconfig eth0 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.0.100 netmask 255.255.255.0 broadcast 10.0.0.255 inet6 fe80::345d:38a5:8df5:e4e9 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:8b:2e:bb txqueuelen 1000 (Ethernet) RX packets 485 bytes 43391 (42.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 294 bytes 35220 (34.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@lixian ~]#
3.hostname命令
hostname -i -I
-i 显示是IPV6和IPV4的信息
-I 只显示ip地址
[root@lixian ~]#hostname -i fe80::345d:38a5:8df5:e4e9%eth0 10.0.0.100 [root@lixian ~]#hostname -I 10.0.0.100 [root@lixian ~]#