网络配置文件详解
网卡配置文件
ONBOOT:在系统引导时是否激活此设备 TYPE:接口类型;常见有的Ethernet, Bridge BOOTPROTO:值为none(表示手动设置IP地址) UUID:设备的惟一标识 IPADDR:指明IP地址 NETMASK:子网掩码或者PREFIX24 GATEWAY: 默认网关 DNS1:第一个DNS服务器指向 DNS2:第二个DNS服务器指向 USERCTL:普通用户是否可控制此设备 PEERDNS:如果BOOTPROTO的值为“dhcp”,是否允许 dhcp server分配的dns服务器指向信息直接覆盖至
添加别名网卡地址
[root@mail ~]# ifconfig eth0:1 10.50.50.12/24 [root@mail ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:8B:16:7F inet addr:192.168.10.36 Bcast:192.168.10.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe8b:167f/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:430542 errors:0 dropped:0 overruns:0 frame:0 TX packets:11685 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:32514707 (31.0 MiB) TX bytes:734729 (717.5 KiB) eth0:1 Link encap:Ethernet HWaddr 00:0C:29:8B:16:7F inet addr:10.50.50.12 Bcast:10.50.50.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 [root@mail ~]# ifconfig eth0:1 down [root@mail ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:8B:16:7F inet addr:192.168.10.36 Bcast:192.168.10.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe8b:167f/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:430670 errors:0 dropped:0 overruns:0 frame:0 TX packets:11719 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:32524535 (31.0 MiB) TX bytes:739041 (721.7 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
多网卡绑定一个IPbonding
Mode 0 (balance-rr):轮转(Round-robin)策略:从头到尾顺序的在每一个slave接口上面发送数据包。本模式提供负载均衡和容错的能力
Mode 1 (active-backup):活动-备份(主备)策略:只有一个slave被激活,当且仅当活动的slave接口失败时才会激活其他slave。为了避免交换机发生混乱此时绑定的MAC地址只有一个外部端口上可见
Mode 3(broadcast):广播策略:在所有的slave接口上传送所有的报文提供容错
[root@mail ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0 DEVICE=bond0 BOOTPROTO=none IPADDR=192.168.10.37 PREFIX=24 GATEWAY=192.168.10.2 BONDING_OPTS="mode=1 miimon=100"模式为1模式 [root@mail ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet UUID=985636c1-f56c-40fb-b4c0-ff18e376fb22 MASTER=bond0 SLAVE=yes [root@mail ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1 DEVICE=eth1 TYPE=Ethernet MASTER=bond0 SLAVE=yes [root@mail network-scripts]# service network restart [root@mail ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000 link/ether 00:0c:29:8b:16:7f brd ff:ff:ff:ff:ff:ff 3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000 link/ether 00:0c:29:8b:16:7f brd ff:ff:ff:ff:ff:ff 4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP link/ether 00:0c:29:8b:16:7f brd ff:ff:ff:ff:ff:ff inet 192.168.10.37/24 brd 192.168.10.255 scope global bond0 inet6 fe80::20c:29ff:fe8b:167f/64 scope link valid_lft forever preferred_lft forever
查看bond状态信息
[root@mail ~]# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: eth0 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eth0 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:8b:16:7f Slave queue ID: 0 Slave Interface: eth1 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:8b:16:89 Slave queue ID: 0
切换3模式
[root@mail ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0 DEVICE=bond0 BOOTPROTO=none IPADDR=192.168.10.37 PREFIX=24 GATEWAY=192.168.10.2 BONDING_OPTS="mode=3 miimon=100" [root@mail ~]# service network restart 正在关闭接口 bond0: [确定] 关闭环回接口: [确定] 弹出环回接口: [确定] 弹出界面 bond0: Determining if ip address 192.168.10.37 is already in use for device bond0... [root@mail ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000 link/ether 00:0c:29:8b:16:7f brd ff:ff:ff:ff:ff:ff 3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000 link/ether 00:0c:29:8b:16:7f brd ff:ff:ff:ff:ff:ff 4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP link/ether 00:0c:29:8b:16:7f brd ff:ff:ff:ff:ff:ff inet 192.168.10.37/24 brd 192.168.10.255 scope global bond0 inet6 fe80::20c:29ff:fe8b:167f/64 scope link tentative dadfailed valid_lft forever preferred_lft forever [确定] [root@mail ~]# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (broadcast) MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eth0 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:8b:16:7f Slave queue ID: 0 Slave Interface: eth1 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:8b:16:89 Slave queue ID: 0 [root@mail ~]# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (broadcast) MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eth0 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:8b:16:7f Slave queue ID: 0 Slave Interface: eth1 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:8b:16:89 Slave queue ID: 0
查看ping
[root@mast ~]# ping 192.168.10.37 PING 192.168.10.37 (192.168.10.37) 56(84) bytes of data. 64 bytes from 192.168.10.37: icmp_seq=1 ttl=64 time=9.46 ms 64 bytes from 192.168.10.37: icmp_seq=1 ttl=64 time=9.50 ms (DUP!) 64 bytes from 192.168.10.37: icmp_seq=2 ttl=64 time=0.808 ms 64 bytes from 192.168.10.37: icmp_seq=2 ttl=64 time=0.863 ms (DUP!) 64 bytes from 192.168.10.37: icmp_seq=3 ttl=64 time=0.538 ms 64 bytes from 192.168.10.37: icmp_seq=3 ttl=64 time=0.583 ms (DUP!)
删除bond操作
[root@mail ~]# cd /etc/sysconfig/network-scripts/ [root@mail network-scripts]# rm -rf ifcfg-bond0 [root@mail network-scripts]# vim ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet UUID=985636c1-f56c-40fb-b4c0-ff18e376fb22 ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=none HWADDR=00:0C:29:8B:16:7F IPADDR=192.168.10.36 PREFIX=24 GATEWAY=192.168.10.2 DNS1=8.8.8.8 DEFROUTE=yes IPV4_FAILURE_FATAL=yes IPV6INIT=no NAME="System eth0" [root@mail network-scripts]# service network restart 正在关闭接口 eth0: [确定] 关闭环回接口: [确定] 弹出环回接口: [确定] 弹出界面 eth0: Determining if ip address 192.168.10.36 is already in use for device eth0... [确定] [root@mail network-scripts]# ifconfig bond0 down [root@mail network-scripts]# lsmod | grep bond bonding 132885 0 [root@mail network-scripts]# rmmod bonding 卸载模块
centos 7 网络相关设置
修改网卡的命名/etc/grub2.cfg 添加net.ifnames=0;重启
[root@mast network-scripts]# diff /etc/grub2.cfg /etc/grub2.cfg.bakl 100c100 < linux16 /vmlinuz-3.10.0-862.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=zh_CN.UTF-8 net.ifnames=0 --- > linux16 /vmlinuz-3.10.0-862.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=zh_CN.UTF-8
主机名修改
[root@mast ~]# hostnamectl set-hostname chenxi && exec bash [root@chenxi ~]# hostname chenxi
查看网卡配置文件链接
[root@chenxi ~]# nmcli connection show NAME UUID TYPE DEVICE ens33 c96bc909-188e-ec64-3a96-6a90982b08ad ethernet ens33 有线连接 1 f311a268-c621-31f7-b511-c49148f85f08 ethernet ens37
修改配置文件的名字
[root@chenxi ~]# nmcli connection modify 有线连接\ 1 connection.id ens37 [root@chenxi ~]# nmcli connection show NAME UUID TYPE DEVICE ens33 c96bc909-188e-ec64-3a96-6a90982b08ad ethernet ens33 ens37 f311a268-c621-31f7-b511-c49148f85f08 ethernet ens37
添加网络配置文件
[root@chenxi ~]# nmcli connection add con-name chenxi-1 type ethernet ifname ens33 连接“chenxi-1”(36fb46d4-3306-4f65-be1d-90d26e6c82b2) 已成功添加。 [root@chenxi ~]# nmcli connection show NAME UUID TYPE DEVICE ens33 c96bc909-188e-ec64-3a96-6a90982b08ad ethernet ens33 ens37 f311a268-c621-31f7-b511-c49148f85f08 ethernet ens37 chenxi-1 36fb46d4-3306-4f65-be1d-90d26e6c82b2 ethernet -- [root@chenxi ~]# nmcli connection modify chenxi-1 connection.autoconnect yes ipv4.addresses 192.168.10.40/24 ipv4.method manual ipv4.gateway 192.168.10.2 ipv4.dns 8.8.8.8 [root@chenxi ~]# cat /etc/sysconfig/network-scripts/ifcfg-chenxi-1 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=chenxi-1 UUID=36fb46d4-3306-4f65-be1d-90d26e6c82b2 DEVICE=ens33 ONBOOT=yes IPADDR=192.168.10.40 PREFIX=24 GATEWAY=192.168.10.2 DNS1=8.8.8.8 [root@chenxi ~]# nmcli connection up chenxi-1 [root@chenxi ~]# nmcli connection show NAME UUID TYPE DEVICE chenxi-1 36fb46d4-3306-4f65-be1d-90d26e6c82b2 ethernet ens33 ens37 f311a268-c621-31f7-b511-c49148f85f08 ethernet ens37 ens33 c96bc909-188e-ec64-3a96-6a90982b08ad ethernet -- [root@chenxi ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:40:c2:01 brd ff:ff:ff:ff:ff:ff inet 192.168.10.40/24 brd 192.168.10.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet6 fe80::1af5:4cf9:3e47:4bd7/64 scope link noprefixroute valid_lft forever preferred_lft forever 3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:40:c2:0b brd ff:ff:ff:ff:ff:ff inet 192.168.10.133/24 brd 192.168.10.255 scope global noprefixroute dynamic ens37 valid_lft 1196sec preferred_lft 1196sec inet6 fe80::24a2:2585:2b12:e5ab/64 scope link noprefixroute valid_lft forever preferred_lft forever
网桥设置
[root@chenxi ~]# nmcli connection add type bridge con-name br0 ifname br0 ipv4.method manual ipv4.addresses 192.168.10.51/24 连接“br0”(f05c3652-50f0-4dbb-a6cd-b82d51832a74) 已成功添加。 [root@chenxi ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:40:c2:01 brd ff:ff:ff:ff:ff:ff inet 192.168.10.40/24 brd 192.168.10.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet6 fe80::1af5:4cf9:3e47:4bd7/64 scope link noprefixroute valid_lft forever preferred_lft forever 3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:40:c2:0b brd ff:ff:ff:ff:ff:ff inet 192.168.10.133/24 brd 192.168.10.255 scope global noprefixroute dynamic ens37 valid_lft 1251sec preferred_lft 1251sec inet6 fe80::24a2:2585:2b12:e5ab/64 scope link noprefixroute valid_lft forever preferred_lft forever 4: br0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000 link/ether ba:0d:53:8d:da:ea brd ff:ff:ff:ff:ff:ff inet 192.168.10.51/24 brd 192.168.10.255 scope global noprefixroute br0 valid_lft forever preferred_lft forever [root@chenxi ~]# nmcli connection add type bridge-slave ifname ens37 master br0 连接“bridge-slave-ens37”(67f5427f-a911-4135-bb96-0ad46061f6ec) 已成功添加。 [root@chenxi ~]# nmcli connection add type bridge-slave ifname ens33 master br0 连接“bridge-slave-ens33”(06ffd910-b441-4ac5-aa1c-eef4da302836) 已成功添加。 [root@chenxi ~]# nmcli connection show NAME UUID TYPE DEVICE br0 f05c3652-50f0-4dbb-a6cd-b82d51832a74 bridge br0 chenxi-1 36fb46d4-3306-4f65-be1d-90d26e6c82b2 ethernet ens33 ens37 f311a268-c621-31f7-b511-c49148f85f08 ethernet ens37 bridge-slave-ens33 06ffd910-b441-4ac5-aa1c-eef4da302836 ethernet -- bridge-slave-ens37 67f5427f-a911-4135-bb96-0ad46061f6ec ethernet -- ens33 c96bc909-188e-ec64-3a96-6a90982b08ad ethernet -- [root@chenxi ~]# nmcli connection up bridge-slave-ens37 连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/5) [root@chenxi ~]# nmcli connection up bridge-slave-ens33 连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/6) [root@chenxi ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000 link/ether 00:0c:29:40:c2:01 brd ff:ff:ff:ff:ff:ff 3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000 link/ether 00:0c:29:40:c2:0b brd ff:ff:ff:ff:ff:ff 4: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 00:0c:29:40:c2:01 brd ff:ff:ff:ff:ff:ff inet 192.168.10.51/24 brd 192.168.10.255 scope global noprefixroute br0 valid_lft forever preferred_lft forever inet6 fe80::68de:39ed:8be:e421/64 scope link noprefixroute valid_lft forever preferred_lft forever
删除网桥配置
[root@chenxi ~]# nmcli connection down br0
草都可以从石头缝隙中长出来更可况你呢