采用传统的命名方式
- 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