Centos7網(wǎng)絡(luò)

采用傳統(tǒng)的命名方式
  • 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"
  • 運(yùn)行此命令grub2-mkconfig -o /etc/grub.cfg 修改/boot/groub2/grub.cfg
  • 重啟系統(tǒng)生效注意修改
修改主機(jī)名
  • hostnamectl set-hostname 主機(jī)名 既時(shí)生效 此文件創(chuàng)建一個(gè)/etc/hostname文件,此文件是centos的主機(jī)名的文件
  • centos6 主機(jī)名永久設(shè)置此文件/etc/sysconfig/network文件
  • hostname臨時(shí)設(shè)置主機(jī)名 centoso7也支持

nmcli 網(wǎng)絡(luò)設(shè)置工具

列出主機(jī)上所有的配置文件

[root@chenxi ~]# nmcli connection show 列出主機(jī)上所有的配置文件

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 創(chuàng)建新的網(wǎng)絡(luò)的配置文件
  • [root@chenxi ~]# nmcli connection add con-name eth0-fh type ethernet ifname eth0 ipv4.method manual ipv4.addresses 192.168.25.1/24 創(chuàng)建新的網(wǎng)絡(luò)配置文件手動(dòng)設(shè)置IP地址 IP地址是192.168.25.1/24
  • [root@chenxi ~]# nmcli connection show 查看是否創(chuàng)建成功
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 查看關(guān)于eth0-fh更詳細(xì)的信息(信息過(guò)長(zhǎng)省略)
  • [root@chenxi ~]# nmcli connection modify eth0-fh connection.autoconnect yes ipv4.dns 8.8.8.8 ifname eth1 修改關(guān)于eth0-fh的一些信息包括綁定的網(wǎng)卡
  • nmcli connection up eth0-fh 啟用網(wǎng)絡(luò)配置文件
  • [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    網(wǎng)絡(luò)物理設(shè)備
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  --     
一個(gè)綁定多個(gè)IP地址
  • [root@chenxi ~]# nmcli connection modify eth0-fh +ipv4.addresses 192.168.56.7/24綁定多一個(gè)IP地址
  • [root@chenxi ~]# nmcli connection modify eth0-fh +ipv4.addresses 192.168.88.99/24多第二個(gè)地址;
  • [root@chenxi ~]# nmcli connection down eth0-fh 關(guān)閉
  • [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 查看設(shè)備的詳細(xì)信息
  • [root@chenxi ~]# nmcli device disconnect eth1 禁用網(wǎng)卡上的ip地址
  • [root@chenxi ~]# nmcli device connect eth1 啟用網(wǎng)卡上的ip地址
多網(wǎng)卡綁定bond的設(shè)備
  • [root@chenxi ~]# nmcli connection add type bond con-name bond0 ifname bond0 創(chuàng)建bond的設(shè)備
    [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 為設(shè)備創(chuàng)建配置文件及設(shè)置IP地址
  • [root@chenxi ~]# nmcli connection add type bond-slave ifname eth1 master bond0 綁定物理設(shè)備
  • [root@chenxi ~]# nmcli connection up bond-slave-eth1 啟動(dòng)從網(wǎng)卡
    以啟用物理網(wǎng)卡的地址將失效
  • [root@chenxi ~]# nmcli connection up bond0 啟用bond邏輯設(shè)備
  • nmcli con dewn bend0 停止bend0設(shè)備
  • nmcli connection delete bond-slave-eth0 刪除網(wǎng)卡綁定的文件
  • nmcli con delete bond0 刪除bond0wenjian
  • nmcli con reload 重新加載
    查看bond的詳細(xì)信息需要裝kerenl-dol包;查看cat /usr/share/doc/kernel-doc-3.10.0/Documentation/networking/bonding.txt 文件
  • 監(jiān)控bond狀態(tài)文件
    cat /proc/net/bonbing/bond0
網(wǎng)絡(luò)組
  • nmcli connection add type team con-name team0 ifname team0 config '{"{runner}":{"name":"activebacku"}}' 創(chuàng)建網(wǎng)絡(luò)組文件 選擇的工作模式 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 設(shè)置網(wǎng)絡(luò)組的ip地址
  • [root@chenxi yum.repos.d]# nmcli connection up team0 啟用網(wǎng)絡(luò)組的配置
  • [root@chenxi yum.repos.d]# nmcli connection add type team-slave ifname eth1 master team0 添加物理網(wǎng)卡
  • [root@chenxi yum.repos.d]# nmcli connection add type team-slave ifname eth0 master team0 添加物理網(wǎng)卡
  • [root@chenxi yum.repos.d]# nmcli connection up team-slave-eth1 啟用網(wǎng)絡(luò)組網(wǎng)卡綁定文件
    刪除網(wǎng)絡(luò)組
    nmcli connection down team0 停止服務(wù)
    teamdctl team0 state
    nmcli connection show
    nmcli connectioni delete team0-eth0
    nmcli connectioni delete team0-eth1
    nmcli connection show
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容