centos6
主機(jī)名
/etc/sysconfig/network
hostname redhat:當(dāng)前生效
vim /etc/sysconfig/network:重啟后生效
網(wǎng)卡名
/etc/udev/rules.d/70-persistent-net.rules
修改網(wǎng)卡名
-
修改網(wǎng)卡的名字
[root@centos6 network-scripts]# vim /etc/udev/rules.d/70-persistent-net.rules
-
修改網(wǎng)卡配置文件的名字
[root@centos6 network-scripts]# mv ifcfg-eth3 ifcfg-eth2
-
修改配置文件中的網(wǎng)卡名字
[root@centos6 network-scripts]# vim ifcfg-eth3
-
查看網(wǎng)卡模塊
[root@centos6 network-scripts]# ethtool -i eth2
-
重啟網(wǎng)卡模塊
[root@centos6 network-scripts]# modprobe -r e1000 [root@centos6 network-scripts]# modprobe e1000
配置bonding
創(chuàng)建bonding
-
增加網(wǎng)卡并配置bond0文件
[root@centos6 ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0 DEVICE=bond0 ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static BONDING_OPTS="miimon=100 mode=1" IPADDR=1.1.1.1 NETMASK=255.255.255.0
-
配置網(wǎng)卡文件
[root@centos6 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth3 DEVICE=eth3 HWADDR=00:50:56:3d:28:04 TYPE=Ethernet ONBOOT=yes MASTER=bond0 SLAVE=yes [root@centos6 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth4 EVICE=eth4 HWADDR=00:50:56:37:2b:03 TYPE=Ethernet ONBOOT=yes MASTER=bond0 SLAVE=yes
-
重啟網(wǎng)絡(luò)服務(wù)
[root@centos6 ~]# service network restart
-
查看bond狀態(tài)
[root@centos6 ~]# cat /proc/net/bonding/bond0 [root@centos6 ~]# cat /sys/class/net/bond0/bonding/mode
刪除bonding
-
禁用bond0
[root@centos6 ~]# ifconfig bond0 down
-
卸載bonding模塊
[root@centos6 ~]# modprobe -r bonding [root@centos6 ~]# rmmod bonding
-
刪除bond0及相關(guān)網(wǎng)卡的配置文件
[root@centos6 ~]# rm /etc/sysconfig/network-scripts/ifcfg-bond0 [root@centos6 ~]# rm /etc/sysconfig/network-scripts/ifcfg-eth{3,4}
-
可以選擇再將模塊加載
[root@centos6 ~]# modprobe bonding
centos7
主機(jī)名
/etc/hostname
默認(rèn)無文件肺樟,通過DNS反向解析獲取主機(jī)名税肪,主機(jī)名默認(rèn)為:localhost.localdomain
hostnamectl set-hostname redhat:修改主機(jī)名,立即生效并寫入配置文件
網(wǎng)卡名
修改網(wǎng)卡命名方式為傳統(tǒng)命名方式,為方便自動(dòng)化運(yùn)維愧薛,通常會(huì)修改
修改網(wǎng)卡名
-
先修改命名方式,兩種修改方式原理相同
# 方法一 [root@centos7 ~]# vim /boot/grub2/grub.cfg 在linux16...行的尾加上net.ifnames=0 # 方法二 [root@centos7 ~]# vim /etc/default/grub 在rhgb quiet后面加上 net.ifnames=0 [root@centos7 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg 重新生成帶net.ifnames=0配置的新grub.cfg文件
-
修改配置文件衫画,先改配置文件名稱毫炉,再改配置文件中的設(shè)備名稱
[root@centos7 ~]# mv ifcfg-ens33 ifcfg-eth0 [root@centos7 ~]# vim ifcfg-eth0 修改DEVICE
重啟系統(tǒng)
nmcli
基本配置
禁用指定網(wǎng)絡(luò)接口:nmcli device disconnect eth0
啟用指定網(wǎng)絡(luò)接口:nmcli device connect eth0
顯示網(wǎng)絡(luò)接口屬性:nmcli decice show eth0
顯示設(shè)備狀態(tài):nmcli device status
創(chuàng)建新連接:nmcli connection add type ethernet con-name eth2-redhat ifname eth2(/etc/sysconfig/network-scripts/下的配置文件名稱為初次創(chuàng)建時(shí)指定的名稱,以后修改只是修改配置文件中的名稱削罩,而不會(huì)修改配置文件本身的名稱)
修改連接名稱:nmcli connection modify eth2-redhat con-name eth2-redhat
修改連接配置:nmcli connection modify eth0-office ipv4.method manual ipv4.addresses 1.1.1.1/24 ipv4.gateway 1.1.1.254 ipv4.dns 8.8.8.8
切換連接配置:nmcli connection up eth0-office
顯示所有連接(包括不活動(dòng)的):nmcli connection show
顯示所有活動(dòng)連接:nmcli connection show --active
顯示網(wǎng)絡(luò)連接配置:nmcli connection show ens33-hi
增加ipv4.address:nmcli connection modify eth0-office +ipv4.addresses 3.3.3.3/24
減少ipv4.address:nmcli connection modify eth0-office -ipv4.addresses 3.3.3.3/24
重讀配置:nmcli connection reload(nmcli直接修改配置瞄勾,up一下即可生效,如果直接修改配置文件弥激,要使用reload將硬盤中的配置文件讀入內(nèi)存进陡,再up重讀配置才能生效)
DHCP時(shí)不自動(dòng)獲取DNS:nmcli connection modify eth0-office ipv4.ignore-auto-dns yes(當(dāng)IP通過dhcp自動(dòng)獲取時(shí),dns仍是手動(dòng)設(shè)置微服,不自動(dòng)獲取趾疚,相當(dāng)于讀取配置文件中DNS地址)
刪除配置文件:nmcli connection delete ens33
配置bonding
創(chuàng)建bonding
-
增加bond配置文件
[root@centos7 ~]# nmcli connection add type bond con-name bond0 ifname bond0 mode active-backup
-
將物理網(wǎng)卡作為slave加入bond
[root@centos7 ~]# nmcli connection add type bond-slave ifname eth2 con-name bond-slave-eth2 master bond0 [root@centos7 ~]# nmcli connection add type bond-slave ifname eth3 con-name bond-slave-eth3 master bond0
-
給bond0設(shè)置ip
[root@centos7 ~]# nmcli connection modify bond0 ipv4.method manual ipv4.addresses 1.1.1.1/24
-
啟用slave
[root@centos7 ~]# nmcli connection up bond-slave-eth2 [root@centos7 ~]# nmcli connection up bond-slave-eth3
-
啟用bonding
[root@centos7 ~]# nmcli connection up bond0
配置team
創(chuàng)建team
-
增加team配置文件
[root@centos7 ~]# nmcli connection add type team con-name team0 ifname team0 config '{"runner": {"name": "loadbalance"}}'
-
將物理網(wǎng)卡作為slave加入team
[root@centos7 ~]# nmcli connection add type team-slave con-name team0-slave-eth2 ifname eth2 master team0 [root@centos7 ~]# nmcli connection add type team-slave con-name team0-slave-eth3 ifname eth3 master team0
-
給team0設(shè)置ip
[root@centos7 ~]# nmcli connection modify team0 ipv4.method manual ipv4.addresses 1.1.1.1/24
-
啟用slave
[root@centos7 ~]# nmcli connection up bond-slave-eth2 [root@centos7 ~]# nmcli connection up bond-slave-eth3
啟用team
-
修改或查看team
[root@centos7 ~]# nmcli connection modify team0 team.config '{"runner": {"name": "activebackup"}}' [root@centos7 ~]# teamdctl team0 state
配置bridge
創(chuàng)建bridge
-
增加bridge配置文件
[root@centos7 ~]# nmcli connection add type bridge con-name br0 ifname br0
-
將物理網(wǎng)卡作為slave加入bridge
[root@centos7 ~]# nmcli connection add type bridge-slave con-name br0-eth4 ifname eth4 master br0
-
修改bridge配置
[root@centos7 ~]# nmcli connection modify br0 ipv4.method manual ipv4.addresses 2.2.2.2/24
-
啟用查看bdidge
[root@centos7 ~]# nmcli connection up br0 [root@centos7 ~]# brctl show
-
刪除bridge中的網(wǎng)卡
[root@centos7 ~]# brctl delif br0 eth4