CentOS 7 查看IP、Gateway、DNS、Hostname
查看 IP:ip addr
[root@192 ~]# ip addr
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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:09:3d:c1 brd ff:ff:ff:ff:ff:ff
inet 192.168.2.194/24 brd 192.168.2.255 scope global noprefixroute dynamic ens33 # 查询得到IP地址为192.168.2.194
valid_lft 41947sec preferred_lft 41947sec
inet6 2408:824c:613:3770:2a4f:4157:ded6:2954/64 scope global noprefixroute dynamic
valid_lft 251131sec preferred_lft 164731sec
inet6 fe80::1b87:c6ea:ecd3:b08c/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:63:e9:c7 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:63:e9:c7 brd ff:ff:ff:ff:ff:ff
查看路由:ip route
[root@192 ~]# ip route
default via 192.168.2.1 dev ens33 proto dhcp metric 100 # 查询得到路由为192.168.2.1
192.168.2.0/24 dev ens33 proto kernel scope link src 192.168.2.194 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
查看DNS
- 查看本地配置文件:
cat /etc/resolv.conf
[root@192 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search lan
nameserver 192.168.2.1
nameserver fe80::1%ens33
- 用
dig
、nslookup
查询 DNS 命令
不能使用 dig、nslookup,先安装相应软件包:yum install -y bind-utils
[root@192 ~]# yum install -y bind-utils
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.nju.edu.cn
* extras: mirrors.nju.edu.cn
* updates: mirrors.nju.edu.cn
软件包 32:bind-utils-9.11.4-26.P2.el7_9.15.x86_64 已安装并且是最新版本
无须任何处理
[root@192 ~]#
使用 dig www.baidu.com
命令
[root@192 ~]# dig www.baidu.com
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.15 <<>> www.baidu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2739
;; flags: qr ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.baidu.com. IN A
;; ANSWER SECTION:
www.baidu.com. 253 IN CNAME www.a.shifen.com.
www.a.shifen.com. 108 IN A 153.3.238.110
www.a.shifen.com. 108 IN A 153.3.238.102
;; Query time: 9 msec
;; SERVER: 192.168.2.1#53(192.168.2.1)
;; WHEN: 四 4月 25 22:15:36 CST 2024
;; MSG SIZE rcvd: 90
使用 nslookup www.baidu.com
命令
[root@192 ~]# nslookup www.baidu.com
Server: 192.168.2.1
Address: 192.168.2.1#53
Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 153.3.238.102
Name: www.a.shifen.com
Address: 153.3.238.110
Name: www.a.shifen.com
Address: 2408:873d:22:1a01:0:ff:b087:eecc
Name: www.a.shifen.com
Address: 2408:873d:22:18ac:0:ff:b021:1393
查看主机名:hostname
[root@192 ~]# cat /etc/hostname
localhost.localdomain
[root@192 ~]# hostname
192.168.2.194
[root@192 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6