Linux-网络管理

18. linux 网络管理

18.1 网卡命名管理

$# 1. 给linux添加一块网卡(网络适配器) - vMnet11

# 查看网卡信息
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.152  netmask 255.255.255.0  broadcast 192.168.8.255
        inet6 fe80::f3b3:cb7d:dd78:78ca  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:3f:96:8d  txqueuelen 1000  (Ethernet)
        RX packets 134  bytes 12008 (11.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 98  bytes 14397 (14.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@localhost ~]# 

# 早期linux网卡命名方法
	1. 有线网卡 	eth0/eth1
	2. 无线网卡 	wlan0/wlan1
	3. 本地环回网卡  lo0
	
# 后期linux网卡命名方法
	前两位 + 设备类型 + 设备索引/哈希值
	
前两位:
	en: Ethernet - 有线
	wl: Wireless - 无线
	lo: Loopback - 本地环回
	
设备类型
	o: 	On-board - 板载网卡 
	s: 	hotplug Slot - 热插拔网卡 
	p*s*:	PCI / Slot  - PCI网卡
	
哈希值 | 索引值  系统自动判断生成 - dmidecode
eno网卡哈希值
ens网卡索引值
enp*s*[PCI bus id] s[slot id]

eno16777736

ens33
ens37

enp0s3
enp3s0 : 3号pci总线,0号插槽

wlp*s*
wlp3s0
======================================================================================

$# 2. 调整网卡命令规则方式
[root@localhost ~]# more /etc/sysconfig/grub
6 GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap
rhgb quiet" 
[root@localhost ~]# 

# 添加: "net.ifname=0 biosdevname=0"
[root@localhost ~]# vim /etc/sysconfig/grub
6 GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet net.ifnames=0 biosdevname=0"
[root@localhost ~]# 

[root@localhost ~]# more /boot/grub2/grub.cfg

# 重新生成grub启动加载配置文件
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg

# 删除规则配置文件
[root@localhost ~]# rm -rf /etc/udev/rules.d/70-persistent-ipoib.rules 

[root@localhost ~]# reboot




18.2 网卡配置文件

# Linux主机如果网卡能够持续运行,需要通过配置文件记录网卡相关信息
[root@localhost ~]# cd /etc/sysconfig/network-scripts
[root@localhost network-scripts]# ls

# 网卡配置文件名称 - ifcfg-[网卡名称]
[root@localhost network-scripts]# more ifcfg-ens33
TYPE=Ethernet   	# 网卡类型
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none # boot protocol  网卡地址启动类型 dhcp动态获取 / none | static 静态获取
DEFROUTE=yes   # default route | 是否生成默认路由
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33   # 网卡名称
UUID=f5cf366a-83e3-4a3d-94b4-0387601110ac # 网卡唯一标识符
DEVICE=ens33 # 网卡设备硬件对应名称(必须得改)
ONBOOT=yes	 # 该网卡是否开机自动启动 | 网络服务重启/重启时是否加载该配置文件
DNS1=192.168.8.2
IPADDR=192.168.8.152
PREFIX=24
GATEWAY=192.168.8.2
======================================================================================



$# 2. 修改配置文件
[root@localhost network-scripts]# cp ifcfg-ens33 ./ifcfg-eth0
[root@localhost network-scripts]# cp ifcfg-ens33 ./ifcfg-eth1
[root@localhost network-scripts]# rm -rf ifcfg-ens33
[root@localhost network-scripts]# vim ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=none
NAME=eth0
DEVICE=eth0
ONBOOT=yes
DNS1=192.168.8.2
IPADDR=192.168.8.152
PREFIX=24
GATEWAY=192.168.8.2
[root@localhost network-scripts]#   

[root@localhost network-scripts]# vim ifcfg-eth1
TYPE=Ethernet
BOOTPROTO=none
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=192.168.11.152
PREFIX=24
[root@localhost network-scripts]#   

[root@localhost network-scripts]# systemctl restart network

[root@localhost ~]# ip add show
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:3f:96:8d brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.152/24 brd 192.168.8.255 scope global eth0
    
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:8a:3e:f1 brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.152/24 brd 192.168.11.255 scope global eth1
[root@localhost ~]# 

[root@localhost ~]# route -n 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.8.2     0.0.0.0         UG    100    0        0 eth0(默认路由)
192.168.8.0     0.0.0.0         255.255.255.0   U     100    0        0 eth0(直连路由)
192.168.11.0    0.0.0.0         255.255.255.0   U     100    0        0 eth1(直连路由)
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
[root@localhost ~]# 




18.3 网络接口管理

$# 1. 网络接口查看
ifconfig
ifconfig -a # 查看所有
ifconfig eth0

ip add show
ip add show dev eth0
ip link

#
[root@localhost ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.152  netmask 255.255.255.0  broadcast 192.168.8.255
        inet6 fe80::250:56ff:fe3f:968d  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:3f:96:8d  txqueuelen 1000  (Ethernet)
        RX packets 2006  bytes 139363 (136.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 709  bytes 95425 (93.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        
eth0: 网卡硬件名称
flags: 网卡标志    - 包含网卡-系列状态 <>
UP: 管理状态UP - 管理员未将网卡关闭 | Master State
BROADCAST: 该接口支持广播消息
MULTICAST: 该接口支持组播消息
UNICAST:   该接口支持单播消息
RUNNING: 网卡线路正常	(网线/光纤/虚拟链接)
mtu(mrt) 1500:	该接口最大传输单元
t: transit 发送
r: receive 接受
inet: IPV4地址 / netmask 子网掩码/ broadcast 广播地址
inet6: IPV6相关信息
ether: MAC地址 
txqueuelen: 数据发送缓冲区长度
packets: 包的数量
bytes: 字节数
errors: 错误包总数
dropped: 丢弃包 - 内存不足导致数据丢弃

overruns: 网卡缓冲区溢出导致数据错误-无法处理
frame: 数据帧CRC/FCS序列值校验失败 - 物理信号不稳定导致的传输问题
carrier: 物理设备数据载波絮乱-数据错误
collisions: 物理线路CSMA/CD监听数据冲突

LOWER_UP (网卡线路正常) /  NO-CARRIER (网卡线路不正常) 

state (管理员设置关闭 or 网络线路异常) down

[root@localhost ~]# 


$# 1. 网络接口配置文件卸载/加载 - (网卡和配置文件解除关联)
[root@localhost ~]# ifdown eth0
Device 'eth0' successfully disconnected.
[root@localhost network-scripts]# more ifdown

[root@localhost network-scripts]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:50:56:3f:96:8d  txqueuelen 1000  (Ethernet)    # 状态正常,地址没了
        RX packets 392  bytes 46234 (45.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 192  bytes 25891 (25.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@localhost network-scripts]# 

[root@localhost network-scripts]# ifup eth0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
[root@localhost network-scripts]# 



$# 2. 网络接口开启/关闭
# 关闭
[root@localhost network-scripts]# ifconfig eth0 down
[root@localhost network-scripts]# ifconfig eth0
eth0: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:50:56:3f:96:8d  txqueuelen 1000  (Ethernet)
[root@localhost network-scripts]# 

# 开启
[root@localhost network-scripts]# ifconfig eth0 up
[root@localhost network-scripts]# ifconfig eth0 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.152  netmask 255.255.255.0  broadcast 192.168.8.255
        inet6 fe80::250:56ff:fe3f:968d  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:3f:96:8d  txqueuelen 1000  (Ethernet)
[root@localhost network-scripts]# 
======================================================================================
ip link set eth0 down
ip link set eth0 up
======================================================================================


$# 3. 查看网卡硬件详细信息
[root@localhost network-scripts]# ethtool eth0
Settings for eth0:
	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
[root@localhost network-scripts]# 




18.4 网络服务管理

$# 1. 网络服务
network      
NetworkManager.service

centos6 network 
centos7 network / NetworkManager.service
centos8 NetworkManager.service

$# 2. 两种的区别
NetworkManager.service		支持多种网络管理办法
	GUI
   *nmcli (NetworkManager Conmmand Line Interface) 
	nmtui (NetworkManager Terminal User Interface)

NetworkManager.service		支持管理多种网络类型
有线网络/无线网络/VPN网络/桥接网络 etc..

NetworkManager.service	更加灵活管理网卡与配置文件,真正做到解耦合

$# 3. 建议使用NetworkManager.service
[root@localhost ~]# systemctl stop network && systemctl disable network && systemctl mask network
network.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig network off
Created symlink from /etc/systemd/system/network.service to /dev/null.
[root@localhost ~]# 
[root@localhost ~]# ping 192.168.8.2
connect: Network is unreachable
[root@localhost ~]# 





18.5 nmcli网络管理

nmcli - NetworkManager.service网络服务管理中的一种网络管理工具

$# 1. 
[root@localhost ~]# nmcli device status
DEVICE      TYPE      STATE         CONNECTION 
virbr0      bridge    connected     virbr0     
eth0        ethernet  disconnected  --         
eth1        ethernet  disconnected  --         
lo          loopback  unmanaged     --         
virbr0-nic  tun       unmanaged     --         
[root@localhost ~]# 
DEVICE: 网卡设备名称 

TYPE:	网卡类型
	ethernet 
 	loopback
 	bridge: 虚拟网桥/虚拟交换机
  	tun:	虚拟网卡
  	
STATE: 网卡状态
  connected:	已经链接到配置文件  
  disconnected:	未已经链接到配置文件  
  unmanaged: 未受NetworkManager管理 (添加链接信息进行管理)  

CONNECTION: 当前网卡加载到链接信息,网卡配置文件



[root@localhost ~]# nmcli connection show
NAME                UUID                                  TYPE            DEVICE 
virbr0              cf57cafd-c2b8-49a7-814c-201bad225a00  bridge          virbr0 
Wired connection 1  dee7c67b-dd99-35de-b2ff-2699d21d05ac  802-3-ethernet  --     
eth0                5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  802-3-ethernet  --     
eth1                9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  802-3-ethernet  --     
[root@localhost ~]# 

NAME - 配置文件信息 
UUID - 网卡connection配置文件唯一标识符                                 
TYPE - 网卡类型          
DEVICE - 网卡设备名称 


$# 2. 网络配置 文件关联
[root@localhost ~]# nmcli connection  up eth0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/8)
[root@localhost ~]# 

[root@localhost ~]# nmcli device connect eth1
Device 'eth1' successfully activated with '9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04'.
[root@localhost ~]# 


$# 3. 网络配置 文件断开关联
[root@localhost ~]# nmcli connection  down eth0
Connection 'eth0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/8)
[root@localhost ~]# nmcli device disconnect eth1
Device 'eth1' successfully disconnected.
[root@localhost ~]# 


$# 4. 网络connection配置文件添加
oot@localhost network-scripts]# 
[root@localhost network-scripts]# nmcli connection add con-name static-ip-eth1 autoconnect yes type ethernet ifname eth1 ip4 192.168.11.153/24
Connection 'static-ip-eth1' (d9b0c44a-9038-4306-9a25-13d491b8cc7e) successfully added.
[root@localhost network-scripts]# 
[root@localhost network-scripts]# nmcli connection  show
NAME                UUID                                  TYPE            DEVICE 
virbr0              cf57cafd-c2b8-49a7-814c-201bad225a00  bridge          virbr0 
Wired connection 1  dee7c67b-dd99-35de-b2ff-2699d21d05ac  802-3-ethernet  --     
eth0                5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  802-3-ethernet  --     
eth1                9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  802-3-ethernet  --     
static-ip-eth1      d9b0c44a-9038-4306-9a25-13d491b8cc7e  802-3-ethernet  --     
[root@localhost network-scripts]# ls
ifcfg-eth0             ifcfg-eth1             ifcfg-static-ip-eth1      
[root@localhost network-scripts]# 
    
[root@localhost network-scripts]# nmcli device status
DEVICE      TYPE      STATE         CONNECTION 
virbr0      bridge    connected     virbr0     
eth1        ethernet  connected     eth1       
eth0        ethernet  disconnected  --         
lo          loopback  unmanaged     --         
virbr0-nic  tun       unmanaged     --         
[root@localhost network-scripts]# 

[root@localhost network-scripts]# nmcli connection up static-ip-eth1 
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/17)

[root@localhost network-scripts]# nmcli connection show
NAME                UUID                                  TYPE            DEVICE 
static-ip-eth1      d9b0c44a-9038-4306-9a25-13d491b8cc7e  802-3-ethernet  eth1   
virbr0              cf57cafd-c2b8-49a7-814c-201bad225a00  bridge          virbr0 
Wired connection 1  dee7c67b-dd99-35de-b2ff-2699d21d05ac  802-3-ethernet  --     
eth0                5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  802-3-ethernet  --     
eth1                9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  802-3-ethernet  --     
[root@localhost network-scripts]# 


[root@localhost network-scripts]# ip add show dev eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:8a:3e:f1 brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.153/24 brd 192.168.11.255 scope global eth1  
[root@localhost network-scripts]# 


# 
[root@localhost network-scripts]# nmcli connection add con-name static-ip-eth0 autoconnect yes type ethernet ifname eth0 ip4 192.168.8.153/24 gw4 192.168.8.2
Connection 'static-ip-eth0' (d4adfb0d-7f36-4c4b-b785-8329e0c55dda) successfully added.

[root@localhost network-scripts]# nmcli connection show
NAME                UUID                                  TYPE            DEVICE 
static-ip-eth1      d9b0c44a-9038-4306-9a25-13d491b8cc7e  802-3-ethernet  eth1   
virbr0              cf57cafd-c2b8-49a7-814c-201bad225a00  bridge          virbr0 
Wired connection 1  dee7c67b-dd99-35de-b2ff-2699d21d05ac  802-3-ethernet  --     
eth0                5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  802-3-ethernet  --     
eth1                9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  802-3-ethernet  --     
static-ip-eth0      d4adfb0d-7f36-4c4b-b785-8329e0c55dda  802-3-ethernet  --     
[root@localhost network-scripts]# 


[root@localhost network-scripts]# nmcli connection up static-ip-eth0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/18)
[root@localhost network-scripts]# nmcli connection show
NAME                UUID                                  TYPE            DEVICE 
static-ip-eth0      d4adfb0d-7f36-4c4b-b785-8329e0c55dda  802-3-ethernet  eth0   
static-ip-eth1      d9b0c44a-9038-4306-9a25-13d491b8cc7e  802-3-ethernet  eth1   
virbr0              cf57cafd-c2b8-49a7-814c-201bad225a00  bridge          virbr0 
Wired connection 1  dee7c67b-dd99-35de-b2ff-2699d21d05ac  802-3-ethernet  --     
eth0                5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  802-3-ethernet  --     
eth1                9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  802-3-ethernet  --     
[root@localhost network-scripts]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.153  netmask 255.255.255.0  broadcast 192.168.8.255
        inet6 fe80::89ed:c926:3e3a:3498  prefixlen 64  scopeid 0x20<link>
[root@localhost network-scripts]# 

[root@localhost network-scripts]# 
[root@localhost network-scripts]# 
[root@localhost network-scripts]# ls
ifcfg-eth0    ifcfg-eth1    ifcfg-static-ip-eth0      ifcfg-static-ip-eth1     
[root@localhost network-scripts]# 

$# 5. 网络网卡详细信息查看
[root@localhost network-scripts]# nmcli device show 
[root@localhost network-scripts]# nmcli device show eth0
GENERAL.DEVICE:                         eth0
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         00:50:56:3F:96:8D
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (connected)
GENERAL.CONNECTION:                     static-ip-eth0
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/18
WIRED-PROPERTIES.CARRIER:               on
IP4.ADDRESS[1]:                         192.168.8.153/24
IP4.GATEWAY:                            192.168.8.2
IP6.ADDRESS[1]:                         fe80::89ed:c926:3e3a:3498/64
IP6.GATEWAY:                            --
[root@localhost network-scripts]# 


[root@localhost network-scripts]# nmcli device disconnect eth0
Device 'eth0' successfully disconnected.
[root@localhost network-scripts]# nmcli device show eth0
GENERAL.DEVICE:                         eth0
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         00:50:56:3F:96:8D
GENERAL.MTU:                            1500
GENERAL.STATE:                          30 (disconnected)
GENERAL.CONNECTION:                     --
GENERAL.CON-PATH:                       --
WIRED-PROPERTIES.CARRIER:               on
[root@localhost network-scripts]# 



$# 6. 网络接口开启/关闭

100 (connected)
30 (disconnected)
nmcli connection down
nmcli device disconnect
ifdown

20 (unavailable)
ip link set eth0 down
ifconfig eth0 down

70 (connecting (getting IP configuration))  # 网卡配置文件丢了,DEVICE自己找了个connection


# rm -rf 可能有问题
[root@localhost network-scripts]# 
[root@localhost network-scripts]# rm -rf ifcfg-eth1
[root@localhost network-scripts]# rm -rf ifcfg-eth0
[root@localhost network-scripts]# nmcli connection show
NAME                UUID                                  TYPE            DEVICE 
static-ip-eth1      d9b0c44a-9038-4306-9a25-13d491b8cc7e  802-3-ethernet  eth1   
virbr0              cf57cafd-c2b8-49a7-814c-201bad225a00  bridge          virbr0 
Wired connection 1  dee7c67b-dd99-35de-b2ff-2699d21d05ac  802-3-ethernet  --     
eth0                5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  802-3-ethernet  --     
eth1                9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  802-3-ethernet  --     
static-ip-eth0      d4adfb0d-7f36-4c4b-b785-8329e0c55dda  802-3-ethernet  --     
[root@localhost network-scripts]# 
[root@localhost network-scripts]# nmcli connection delete eth1
Connection 'eth1' (9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04) successfully deleted.
[root@localhost network-scripts]# nmcli connection delete eth0
Connection 'eth0' (5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03) successfully deleted.
[root@localhost network-scripts]# 


# 删除(直接使用nmcli方式)
nmcli connetion delete [connetion-name]
[root@localhost network-scripts]# nmcli connection add con-name test01 autoconnect yes type ethernet ifname eth0  ip4 192.168.8.154/24 gw4 192.168.8.2
Connection 'test01' (d574e7d6-6f05-4036-8037-0961a4d8092d) successfully added.
[root@localhost network-scripts]# 
[root@localhost network-scripts]# ls
ifcfg-static-ip-eth0      ifcfg-static-ip-eth1             ifcfg-test01               
[root@localhost network-scripts]# 
[root@localhost network-scripts]# 
[root@localhost network-scripts]# nmcli connection delete test01 
Connection 'test01' (d574e7d6-6f05-4036-8037-0961a4d8092d) successfully deleted.
[root@localhost network-scripts]# ls
ifcfg-static-ip-eth0     ifcfg-static-ip-eth1      

[root@localhost network-scripts]# 




18.6 修改connection信息

$# 1. 修改connection信息
[root@localhost network-scripts]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.153  netmask 255.255.255.0  broadcast 192.168.8.255
[root@localhost network-scripts]# 
[root@localhost network-scripts]# nmcli connection modify static-ip-eth0 ipv4.addresses 192.168.8.152/24
[root@localhost network-scripts]# ip add show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:3f:96:8d brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.153/24 brd 192.168.8.255 scope global eth0
  [root@localhost network-scripts]#  
[root@localhost network-scripts]# nmcli connection down static-ip-eth0 && nmcli connection up static-ip-eth0
Connection 'static-ip-eth0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/19)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/21)
[root@localhost network-scripts]#
[root@localhost network-scripts]# ip add show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:3f:96:8d brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.152/24 brd 192.168.8.255 scope global eth0   
[root@localhost network-scripts]# 




18.7 DNS管理

$# 1. DNS添加
[root@localhost network-scripts]# 
[root@localhost network-scripts]# ping www.qq.com
^C
[root@localhost network-scripts]# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2012ms
[root@localhost network-scripts]# 
[root@localhost network-scripts]# more /etc/resolv.conf 
# Generated by NetworkManager
[root@localhost network-scripts]# nmcli connection modify static-ip-eth0 ipv4.dns 114.114.114.114
[root@localhost network-scripts]# cat ifcfg-static-ip-eth0
DNS1=114.114.114.114
[root@localhost network-scripts]# more /etc/resolv.conf 
# Generated by NetworkManager
[root@localhost network-scripts]# ping www.qq.com
^C
[root@localhost network-scripts]#
[root@localhost network-scripts]# nmcli connection down static-ip-eth0 && nmcli connection up static-ip-eth0
Connection 'static-ip-eth0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/21)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/23)
[root@localhost network-scripts]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 114.114.114.114
[root@localhost network-scripts]# 

# 添加dns
[root@localhost network-scripts]# nmcli connection modify static-ip-eth0 +ipv4.dns 8.8.8.8
[root@localhost network-scripts]# cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 114.114.114.114
[root@localhost network-scripts]# nmcli connection down static-ip-eth0 && nmcli connection up static-ip-eth0
Connection 'static-ip-eth0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/23)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/25)
[root@localhost network-scripts]# cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 114.114.114.114
nameserver 8.8.8.8
[root@localhost network-scripts]# 

# 删除dns
[root@localhost network-scripts]# nmcli connection modify static-ip-eth0 -ipv4.dns 8.8.8.8
[root@localhost network-scripts]# nmcli connection down static-ip-eth0 && nmcli connection up static-ip-eth0
Connection 'static-ip-eth0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/25)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/27)
[root@localhost network-scripts]# cat /etc/resolv.conf # Generated by NetworkManager
nameserver 114.114.114.114
[root@localhost network-scripts]# 




18.8 DHCP管理

$# 1.
[root@localhost network-scripts]# nmcli connection add con-name dhcp-eth0 autoconnect yes type ethernet ifname eth0 ipv4.method auto
Connection 'dhcp-eth0' (2fcefb20-592a-4f36-ba27-f469b0d81f59) successfully added.
[root@localhost network-scripts]# ls
ifcfg-dhcp-eth0  ifcfg-static-ip-eth0      ifcfg-static-ip-eth1       
[root@localhost network-scripts]# 


### 虚拟网络编辑器的dhcp服务要开启才能使用
# dhcp服务没开
[root@localhost ~]# nmcli connection show
NAME                UUID                                  TYPE            DEVICE 
dhcp-eth0           d454dc39-b697-4a71-a523-abdb159fc268  802-3-ethernet  eth0   
static-ip-eth1      d9b0c44a-9038-4306-9a25-13d491b8cc7e  802-3-ethernet  eth1   
virbr0              212ad7de-1d30-49eb-826b-e7f25e507550  bridge          virbr0 
Wired connection 1  dee7c67b-dd99-35de-b2ff-2699d21d05ac  802-3-ethernet  --     
static-ip-eth0      d4adfb0d-7f36-4c4b-b785-8329e0c55dda  802-3-ethernet  --     
[root@localhost ~]# 
[root@localhost ~]# nmcli connection up dhcp-eth0          # up 不起来
^CError: nmcli terminated by signal Interrupt (2)
[root@localhost ~]# 
[root@localhost ~]# cat /etc/resolv.conf 
# Generated by NetworkManager
search localdomain
[root@localhost ~]# 
[root@localhost ~]# ping www.qq.com
ping: www.qq.com: Name or service not known
[root@localhost ~]# 


======================================================================================
[root@localhost ~]# nmcli connection up dhcp-eth0 
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
[root@localhost ~]# nmcli connection show
NAME                UUID                                  TYPE            DEVICE 
dhcp-eth0           d454dc39-b697-4a71-a523-abdb159fc268  802-3-ethernet  eth0   
static-ip-eth1      d9b0c44a-9038-4306-9a25-13d491b8cc7e  802-3-ethernet  eth1   
virbr0              b7218154-899d-4e34-ae58-bd8d27cebffa  bridge          virbr0 
Wired connection 1  dee7c67b-dd99-35de-b2ff-2699d21d05ac  802-3-ethernet  --     
static-ip-eth0      d4adfb0d-7f36-4c4b-b785-8329e0c55dda  802-3-ethernet  --     
[root@localhost ~]# 
[root@localhost ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.8.2
[root@localhost ~]# ping www.qq.com
PING ins-r23tsuuf.ias.tencent-cloud.net (112.53.42.52) 56(84) bytes of data.
64 bytes from 112.53.42.52 (112.53.42.52): icmp_seq=1 ttl=128 time=51.3 ms
^C
--- ins-r23tsuuf.ias.tencent-cloud.net ping statistics ---
2 packets transmitted, 1 received, 50% packet loss, time 1001ms
rtt min/avg/max/mdev = 51.359/51.359/51.359/0.000 ms
[root@localhost ~]# 




18.9 主机名字管理

$# 1.
# 查看主机名称
[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# nmcli general hostname
localhost.localdomain


# 查看主机名称配置文件
[root@localhost ~]# 
[root@localhost ~]# more /etc/hostname
localhost.localdomain
[root@localhost ~]# 


# 修改主机名称
[root@localhost ~]# hostnamectl set-hostname huawei
[root@localhost ~]# 
[root@localhost ~]# more /etc/hostname
huawei
[root@localhost ~]# 
[root@localhost ~]# nmcli general hostname HCIE
[root@localhost ~]# 
[root@localhost ~]# more /etc/hostname
HCIE
[root@localhost ~]# 

# 重启主机名称服务 | 退出重新登录
[root@localhost ~]# systemctl restart systemd-hostnamed.service 
[root@localhost ~]# 




18.10 网卡图形化管理

$# 1. 了解即可
GUI - 依赖GNONE/KDE图形化界面
nmtui - 不依赖GNONE/KDE图形化界面
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值