采用傳統的命名方式
- vim /etc/default/grub 編輯此文件
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet " 此行后面追加net.finames=0 保存退出
GRUB_DISABLE_RECOVERY="true"
- 運行此命令grub2-mkconfig -o /etc/grub.cfg 修改/boot/groub2/grub.cfg
- 重啟系統生效注意修改
修改主機名
- hostnamectl set-hostname 主機名 既時生效 此文件創建一個/etc/hostname文件,此文件是centos的主機名的文件
- centos6 主機名永久設置此文件/etc/sysconfig/network文件
- hostname臨時設置主機名 centoso7也支持
nmcli 網絡設置工具
列出主機上所有的配置文件
[root@chenxi ~]# nmcli connection show 列出主機上所有的配置文件
NAME UUID TYPE DEVICE
eth0-y 4527c59d-507b-409a-a9f5-6527afeaf9cf 802-3-ethernet eth0
eth1 a4b11117-b4cc-3460-897c-754185b03959 802-3-ethernet eth1
virbr0 d348629e-63a8-493d-9dcc-2e4171b03d70 bridge virbr0
2修改配置文件的名字
[root@chenxi ~]# nmcli connection show
NAME UUID TYPE DEVICE
eth0 7bb5f655-fe1d-31c3-bff1-9804e4d82844 802-3-ethernet eth0
eth1 a4b11117-b4cc-3460-897c-754185b03959 802-3-ethernet eth1
virbr0 d348629e-63a8-493d-9dcc-2e4171b03d70 bridge virbr0
eth0-chenxi a81f7ea2-fb75-43a9-b3dc-fde6cd7a0328 802-3-ethernet --
eth0-y 4527c59d-507b-409a-a9f5-6527afeaf9cf 802-3-ethernet --
eth1-yun 8cacc601-aec0-4265-8d27-c39ed6ea4070 802-3-ethernet --
- [root@chenxi ~]# nmcli connection modify eth0-y connection.id eth0-p 改eth0-y的名字改成eth0-p
- [root@chenxi ~]# nmcli connection show 查看是否修改成功
NAME UUID TYPE DEVICE
eth0 7bb5f655-fe1d-31c3-bff1-9804e4d82844 802-3-ethernet eth0
eth1 a4b11117-b4cc-3460-897c-754185b03959 802-3-ethernet eth1
virbr0 d348629e-63a8-493d-9dcc-2e4171b03d70 bridge virbr0
eth0-chenxi a81f7ea2-fb75-43a9-b3dc-fde6cd7a0328 802-3-ethernet --
eth0-p 4527c59d-507b-409a-a9f5-6527afeaf9cf 802-3-ethernet --
eth1-yun 8cacc601-aec0-4265-8d27-c39ed6ea4070 802-3-ethernet --
3 創建新的網絡的配置文件
- [root@chenxi ~]# nmcli connection add con-name eth0-fh type ethernet ifname eth0 ipv4.method manual ipv4.addresses 192.168.25.1/24 創建新的網絡配置文件手動設置IP地址 IP地址是192.168.25.1/24
- [root@chenxi ~]# nmcli connection show 查看是否創建成功
NAME UUID TYPE DEVICE
eth0 7bb5f655-fe1d-31c3-bff1-9804e4d82844 802-3-ethernet eth0
eth1 a4b11117-b4cc-3460-897c-754185b03959 802-3-ethernet eth1
virbr0 d348629e-63a8-493d-9dcc-2e4171b03d70 bridge virbr0
eth0-chenxi a81f7ea2-fb75-43a9-b3dc-fde6cd7a0328 802-3-ethernet --
eth0-fh ffa21739-6f17-4745-98eb-101e0ddffff6 802-3-ethernet --
eth0-p 4527c59d-507b-409a-a9f5-6527afeaf9cf 802-3-ethernet --
eth1-yun 8cacc601-aec0-4265-8d27-c39ed6ea4070 802-3-ethernet --
- [root@chenxi ~]# nmcli connection show eth0-fh 查看關于eth0-fh更詳細的信息(信息過長省略)
- [root@chenxi ~]# nmcli connection modify eth0-fh connection.autoconnect yes ipv4.dns 8.8.8.8 ifname eth1 修改關于eth0-fh的一些信息包括綁定的網卡
- nmcli connection up eth0-fh 啟用網絡配置文件
- [root@chenxi ~]# nmcli connection show 查看是否已生效
NAME UUID TYPE DEVICE
eth0 7bb5f655-fe1d-31c3-bff1-9804e4d82844 802-3-ethernet eth0
eth0-fh ffa21739-6f17-4745-98eb-101e0ddffff6 802-3-ethernet eth1 網絡物理設備
virbr0 d348629e-63a8-493d-9dcc-2e4171b03d70 bridge virbr0
eth0-chenxi a81f7ea2-fb75-43a9-b3dc-fde6cd7a0328 802-3-ethernet --
eth0-p 4527c59d-507b-409a-a9f5-6527afeaf9cf 802-3-ethernet --
eth1 a4b11117-b4cc-3460-897c-754185b03959 802-3-ethernet --
eth1-yun 8cacc601-aec0-4265-8d27-c39ed6ea4070 802-3-ethernet --
一個綁定多個IP地址
- [root@chenxi ~]# nmcli connection modify eth0-fh +ipv4.addresses 192.168.56.7/24綁定多一個IP地址
- [root@chenxi ~]# nmcli connection modify eth0-fh +ipv4.addresses 192.168.88.99/24多第二個地址;
- [root@chenxi ~]# nmcli connection down eth0-fh 關閉
- [root@chenxi ~]# nmcli connection up eth0-fh 啟用 生效
- 使用 ip a 查詢生效的ip地址
eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:af:1a:36 brd ff:ff:ff:ff:ff:ff
inet 192.168.25.1/24 brd 192.168.25.255 scope global eth1
valid_lft forever preferred_lft forever
inet 192.168.56.7/24 brd 192.168.56.255 scope global eth1
valid_lft forever preferred_lft forever
inet 192.168.88.99/24 brd 192.168.88.255 scope global eth1
valid_lft forever preferred_lft forever
inet6 fe80::3bc0:d8a:b783:ba27/64 scope link
- [root@chenxi ~]# nmcli connection modify eth0-fh -ipv4.addresses 192.168.25.1/24 刪除多余的IP地址重啟生效
- [root@chenxi ~]# nmcli device show 查看設備的詳細信息
- [root@chenxi ~]# nmcli device disconnect eth1 禁用網卡上的ip地址
- [root@chenxi ~]# nmcli device connect eth1 啟用網卡上的ip地址
多網卡綁定bond的設備
- [root@chenxi ~]# nmcli connection add type bond con-name bond0 ifname bond0 創建bond的設備
[root@chenxi ~]# nmcli connection show
NAME UUID TYPE DEVICE
bond0 e04ce09a-49a2-44ab-b7cd-85fb208d9f66 bond bond0
eth0 7bb5f655-fe1d-31c3-bff1-9804e4d82844 802-3-ethernet eth0
eth0-fh ffa21739-6f17-4745-98eb-101e0ddffff6 802-3-ethernet eth1
virbr0 d348629e-63a8-493d-9dcc-2e4171b03d70 bridge virbr0
- [root@chenxi ~]# nmcli connection modify bond0 ipv4.addresses 192.168.74.100/24 ipv4.method manual 為設備創建配置文件及設置IP地址
- [root@chenxi ~]# nmcli connection add type bond-slave ifname eth1 master bond0 綁定物理設備
- [root@chenxi ~]# nmcli connection up bond-slave-eth1 啟動從網卡
以啟用物理網卡的地址將失效 - [root@chenxi ~]# nmcli connection up bond0 啟用bond邏輯設備
- nmcli con dewn bend0 停止bend0設備
- nmcli connection delete bond-slave-eth0 刪除網卡綁定的文件
- nmcli con delete bond0 刪除bond0wenjian
- nmcli con reload 重新加載
查看bond的詳細信息需要裝kerenl-dol包;查看cat /usr/share/doc/kernel-doc-3.10.0/Documentation/networking/bonding.txt 文件 - 監控bond狀態文件
cat /proc/net/bonbing/bond0
網絡組
- nmcli connection add type team con-name team0 ifname team0 config '{"{runner}":{"name":"activebacku"}}' 創建網絡組文件 選擇的工作模式 activebackup
多種方式runner broadcast roundrobin activebackup loadbalance lacp
- [root@chenxi yum.repos.d]# nmcli connection modify team0 ipv4.method manual ipv4.addresses 192.168.74.100/24 設置網絡組的ip地址
- [root@chenxi yum.repos.d]# nmcli connection up team0 啟用網絡組的配置
- [root@chenxi yum.repos.d]# nmcli connection add type team-slave ifname eth1 master team0 添加物理網卡
- [root@chenxi yum.repos.d]# nmcli connection add type team-slave ifname eth0 master team0 添加物理網卡
- [root@chenxi yum.repos.d]# nmcli connection up team-slave-eth1 啟用網絡組網卡綁定文件
刪除網絡組
nmcli connection down team0 停止服務
teamdctl team0 state
nmcli connection show
nmcli connectioni delete team0-eth0
nmcli connectioni delete team0-eth1
nmcli connection show