【CentOS 7筆記42】,監控網絡狀態2#

shallow丿ovelinux


Linux網絡相關git

  • ifconfig #查看網卡ip(yum install net-tools)
  • ifup ens33/ifdown ens33
  • 設定虛擬網卡ens33:1
  • mii-tool ens33 #查看網卡是否鏈接
  • ethtool ens33 #查看網卡是否鏈接
  • 更改主機名hostnamectl set-hostname Linux1
  • DNS配置文件/etc/resolv.conf
  • /etc/hosts文件
[root@localhost ~]# 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: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
		link/ether 00:0c:29:0a:e7:fc brd ff:ff:ff:ff:ff:ff
		inet 192.168.9.134/24 brd 192.168.9.255 scope global eno16777736
		   valid_lft forever preferred_lft forever
		inet6 fe80::20c:29ff:fe0a:e7fc/64 scope link 
		   valid_lft forever preferred_lft forever
[root@localhost ~]# yum reinstall -y net-tools
	Loaded plugins: fastestmirror
	Loading mirror speeds from cached hostfile
	 * epel: mirrors.tongji.edu.cn
	Resolving Dependencies
	--> Running transaction check
	---> Package net-tools.x86_64 0:2.0-0.22.20131004git.el7 will be reinstalled
	--> Finished Dependency Resolution

	Dependencies Resolved

	===================================================================================================
	 Package              Arch              Version                              Repository       Size
	===================================================================================================
	Reinstalling:
	 net-tools            x86_64            2.0-0.22.20131004git.el7             base            305 k

	Transaction Summary
	===================================================================================================
	Reinstall  1 Package

	Total download size: 305 k
	Installed size: 917 k
	Downloading packages:
	net-tools-2.0-0.22.20131004git.el7.x86_64.rpm                               | 305 kB  00:00:00     
	Running transaction check
	Running transaction test
	Transaction test succeeded
	Running transaction
	  Installing : net-tools-2.0-0.22.20131004git.el7.x86_64                                       1/1 
	  Verifying  : net-tools-2.0-0.22.20131004git.el7.x86_64                                       1/1 

	Installed:
	  net-tools.x86_64 0:2.0-0.22.20131004git.el7                                                      

	Complete!

[root@localhost ~]# ifconfig
	eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
			inet 192.168.9.134  netmask 255.255.255.0  broadcast 192.168.9.255
			inet6 fe80::20c:29ff:fe0a:e7fc  prefixlen 64  scopeid 0x20<link>
			ether 00:0c:29:0a:e7:fc  txqueuelen 1000  (Ethernet)
			RX packets 99609  bytes 41662012 (39.7 MiB)
			RX errors 0  dropped 0  overruns 0  frame 0
			TX packets 88315  bytes 21184319 (20.2 MiB)
			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 0  (Local Loopback)
			RX packets 26  bytes 1884 (1.8 KiB)
			RX errors 0  dropped 0  overruns 0  frame 0
			TX packets 26  bytes 1884 (1.8 KiB)
			TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# ifconfig -a
	eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
			inet 192.168.9.134  netmask 255.255.255.0  broadcast 192.168.9.255
			inet6 fe80::20c:29ff:fe0a:e7fc  prefixlen 64  scopeid 0x20<link>
			ether 00:0c:29:0a:e7:fc  txqueuelen 1000  (Ethernet)
			RX packets 99641  bytes 41664576 (39.7 MiB)
			RX errors 0  dropped 0  overruns 0  frame 0
			TX packets 88331  bytes 21186991 (20.2 MiB)
			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 0  (Local Loopback)
			RX packets 26  bytes 1884 (1.8 KiB)
			RX errors 0  dropped 0  overruns 0  frame 0
			TX packets 26  bytes 1884 (1.8 KiB)
			TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

在終端中關閉網卡bash

[root@localhost ~]# ifdown eno16777736

在終端關閉網卡時,會發現終端鏈接異常,而且ifconfig可發現ip異常服務器

[root@localhost ~]# ifconfig
	eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
			ether 00:0c:29:0a:e7:fc  txqueuelen 1000  (Ethernet)
			RX packets 99609  bytes 41662012 (39.7 MiB)
			RX errors 0  dropped 0  overruns 0  frame 0
			TX packets 88315  bytes 21184319 (20.2 MiB)
			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 0  (Local Loopback)
			RX packets 26  bytes 1884 (1.8 KiB)
			RX errors 0  dropped 0  overruns 0  frame 0
			TX packets 26  bytes 1884 (1.8 KiB)
			TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

在主機中啓動網卡網絡

[root@localhost ~]# ifup eno16777736
	Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/17)
[root@localhost ~]# ifconfig
	eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
			inet 192.168.9.134  netmask 255.255.255.0  broadcast 192.168.9.255
			inet6 fe80::20c:29ff:fe0a:e7fc  prefixlen 64  scopeid 0x20<link>
			ether 00:0c:29:0a:e7:fc  txqueuelen 1000  (Ethernet)
			RX packets 100990  bytes 42069350 (40.1 MiB)
			RX errors 0  dropped 0  overruns 0  frame 0
			TX packets 88716  bytes 21235310 (20.2 MiB)
			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 0  (Local Loopback)
			RX packets 26  bytes 1884 (1.8 KiB)
			RX errors 0  dropped 0  overruns 0  frame 0
			TX packets 26  bytes 1884 (1.8 KiB)
			TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

當一臺設備或者服務器有多個網卡時,在調試中可使用ifup 網卡/ifdown 網卡less

[root@localhost ~]# ifdown eno16777736 && ifup eno16777736
	Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/21)

設置虛擬網卡dom

[root@localhost ~]# cd  /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
	ifcfg-eno16777736  ifdown-isdn      ifdown-tunnel  ifup-isdn    ifup-Team
	ifcfg-lo           ifdown-post      ifup           ifup-plip    ifup-TeamPort
	ifdown             ifdown-ppp       ifup-aliases   ifup-plusb   ifup-tunnel
	ifdown-bnep        ifdown-routes    ifup-bnep      ifup-post    ifup-wireless
	ifdown-eth         ifdown-sit       ifup-eth       ifup-ppp     init.ipv6-global
	ifdown-ippp        ifdown-Team      ifup-ippp      ifup-routes  network-functions
	ifdown-ipv6        ifdown-TeamPort  ifup-ipv6      ifup-sit     network-functions-ipv6
[root@localhost network-scripts]# cp ifcfg-eno16777736 ifcfg-eno16777736\:0
[root@localhost network-scripts]# vi !$
vi ifcfg-eno16777736\:0
	HWADDR=00:0C:29:0A:E7:FC
	TYPE=Ethernet
	BOOTPROTO=static
	DEFROUTE=yes
	PEERDNS=yes
	PEERROUTES=yes
	IPV4_FAILURE_FATAL=no
	IPV6INIT=yes
	IPV6_AUTOCONF=yes
	IPV6_DEFROUTE=yes
	IPV6_PEERDNS=yes
	IPV6_PEERROUTES=yes
	IPV6_FAILURE_FATAL=no
	NAME=eno16777736:0
	UUID=18ff95f5-b055-4ad1-baad-74bd36e18654
	DEVICE=eno16777736:0
	ONBOOT=yes
	IPADDR=192.168.9.139
	NETMASK=255.255.255.0
	NETMASK=255.255.255.0
	GATEWAY=192.168.9.2
[root@localhost network-scripts]# ifdown eno16777736 && ifup eno16777736
	Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/22)
[root@localhost network-scripts]# ifconfig
	eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
			inet 192.168.9.134  netmask 255.255.255.0  broadcast 192.168.9.255
			inet6 fe80::20c:29ff:fe0a:e7fc  prefixlen 64  scopeid 0x20<link>
			ether 00:0c:29:0a:e7:fc  txqueuelen 1000  (Ethernet)
			RX packets 106590  bytes 42541671 (40.5 MiB)
			RX errors 0  dropped 9  overruns 0  frame 0
			TX packets 91427  bytes 21585449 (20.5 MiB)
			TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

	eno16777736:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
			inet 192.168.9.139  netmask 255.255.255.0  broadcast 192.168.9.255
			ether 00:0c:29:0a:e7:fc  txqueuelen 1000  (Ethernet)

	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 0  (Local Loopback)
			RX packets 26  bytes 1884 (1.8 KiB)
			RX errors 0  dropped 0  overruns 0  frame 0
			TX packets 26  bytes 1884 (1.8 KiB)
			TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

網卡名字不能夠更改,若配置信息裏沒有DEVICE,則添加一個oop

宿主機ping虛擬機ippost

C:\Users\Administrator>ping 192.168.9.134

	正在 Ping 192.168.9.134 具備 32 字節的數據:
	來自 192.168.9.134 的回覆: 字節=32 時間<1ms TTL=64
	來自 192.168.9.134 的回覆: 字節=32 時間<1ms TTL=64
	來自 192.168.9.134 的回覆: 字節=32 時間<1ms TTL=64
	來自 192.168.9.134 的回覆: 字節=32 時間<1ms TTL=64

	192.168.9.134 的 Ping 統計信息:
		數據包: 已發送 = 4,已接收 = 4,丟失 = 0 (0% 丟失),
	往返行程的估計時間(以毫秒爲單位):
		最短 = 0ms,最長 = 0ms,平均 = 0ms

C:\Users\Administrator>ping 192.168.9.139

	正在 Ping 192.168.9.139 具備 32 字節的數據:
	來自 192.168.9.139 的回覆: 字節=32 時間<1ms TTL=64
	來自 192.168.9.139 的回覆: 字節=32 時間<1ms TTL=64
	來自 192.168.9.139 的回覆: 字節=32 時間<1ms TTL=64
	來自 192.168.9.139 的回覆: 字節=32 時間<1ms TTL=64

	192.168.9.139 的 Ping 統計信息:
		數據包: 已發送 = 4,已接收 = 4,丟失 = 0 (0% 丟失),
	往返行程的估計時間(以毫秒爲單位):
		最短 = 0ms,最長 = 0ms,平均 = 0ms

查看網卡是否鏈接調試

[root@localhost ~]# mii-tool eno16777736
	eno16777736: negotiated 1000baseT-FD flow-control, link ok
[root@localhost ~]# mii-tool eno16777736:0
	eno16777736:0: negotiated 1000baseT-FD flow-control, link ok

有些版本不支持,可使用下面的命令查看

[root@localhost ~]# ethtool eno16777736
	Settings for eno16777736:
		Supported ports: [ TP ]
		Supported link modes:   10baseT/Half 10baseT/Full 
								100baseT/Half 100baseT/Full 
								1000baseT/Full 
		Supported pause frame use: No
		Supports auto-negotiation: Yes
		Advertised link modes:  10baseT/Half 10baseT/Full 
								100baseT/Half 100baseT/Full 
								1000baseT/Full 
		Advertised pause frame use: No
		Advertised auto-negotiation: Yes
		Speed: 1000Mb/s
		Duplex: Full
		Port: Twisted Pair
		PHYAD: 0
		Transceiver: internal
		Auto-negotiation: on
		MDI-X: off (auto)
		Supports Wake-on: d
		Wake-on: d
		Current message level: 0x00000007 (7)
					   drv probe link
		Link detected: yes

更改主機名

[root@localhost ~]# hostname
	localhost.localdomain
[root@localhost ~]# hostnamectl set-hostname linux001
[root@localhost ~]# hostname
	linux001
[root@localhost ~]# bash
[root@linux001 ~]# 
[root@linux001 ~]# exit
[root@localhost ~]# cat /etc/hostname 
	linux001
[root@localhost ~]# logout
Last login: Tue Nov 28 06:41:02 2017 from 192.168.9.1
[root@linux001 ~]#

DNS配置文件

[root@localhost ~]# cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 119.29.29.29
nameserver 114.114.114.114

在網卡的配置文件中定義的

/etc/hosts

[root@localhost ~]# cat /etc/hosts
	127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
	::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

配置lnmp訪問自定義域名

[root@localhost ~]# ping www.qq.com
	PING www.qq.com (120.198.201.156) 56(84) bytes of data.
	64 bytes from 120.198.201.156: icmp_seq=1 ttl=128 time=13.1 ms
	64 bytes from 120.198.201.156: icmp_seq=2 ttl=128 time=20.3 ms
	64 bytes from 120.198.201.156: icmp_seq=3 ttl=128 time=25.7 ms
	^C
	--- www.qq.com ping statistics ---
	3 packets transmitted, 3 received, 0% packet loss, time 2002ms
	rtt min/avg/max/mdev = 13.105/19.734/25.731/5.175 ms
[root@localhost ~]# vi /etc/hosts
	127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
	::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
	192.168.9.134   www.qq.com
[root@localhost ~]# ping www.qq.com
	PING www.qq.com (192.168.9.134) 56(84) bytes of data.
	64 bytes from www.qq.com (192.168.9.134): icmp_seq=1 ttl=64 time=0.018 ms
	64 bytes from www.qq.com (192.168.9.134): icmp_seq=2 ttl=64 time=0.040 ms
	64 bytes from www.qq.com (192.168.9.134): icmp_seq=3 ttl=64 time=0.044 ms
	^C
	--- www.qq.com ping statistics ---
	3 packets transmitted, 3 received, 0% packet loss, time 1999ms
	rtt min/avg/max/mdev = 0.018/0.034/0.044/0.011 ms

只對本機生效,一個ip能夠對應多個域名,hosts解析是先解析的優先級高,以先出現的記錄爲主,從上到下依次執行的,一旦匹配到一個域名就直接解析了,即便後面再出現這域名也不生效

相關文章
相關標籤/搜索