博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
网络配置文件详解
阅读量:5273 次
发布时间:2019-06-14

本文共 15064 字,大约阅读时间需要 50 分钟。

网卡配置文件

ONBOOT:在系统引导时是否激活此设备TYPE:接口类型;常见有的Ethernet, BridgeBOOTPROTO:值为none(表示手动设置IP地址)UUID:设备的惟一标识IPADDR:指明IP地址NETMASK:子网掩码或者PREFIX24GATEWAY: 默认网关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=bond0BOOTPROTO=noneIPADDR=192.168.10.37PREFIX=24GATEWAY=192.168.10.2BONDING_OPTS="mode=1 miimon=100"模式为1模式[root@mail ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0TYPE=EthernetUUID=985636c1-f56c-40fb-b4c0-ff18e376fb22MASTER=bond0SLAVE=yes[root@mail ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1DEVICE=eth1TYPE=EthernetMASTER=bond0SLAVE=yes[root@mail network-scripts]# service network restart[root@mail ~]# ip a1: lo: 
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 forever2: eth0:
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:ff3: eth1:
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:ff4: bond0:
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: NoneCurrently Active Slave: eth0MII Status: upMII Polling Interval (ms): 100Up Delay (ms): 0Down Delay (ms): 0Slave Interface: eth0MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 00:0c:29:8b:16:7fSlave queue ID: 0Slave Interface: eth1MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 00:0c:29:8b:16:89Slave queue ID: 0

  切换3模式

[root@mail ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0 DEVICE=bond0BOOTPROTO=noneIPADDR=192.168.10.37PREFIX=24GATEWAY=192.168.10.2BONDING_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 a1: lo: 
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 forever2: eth0:
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:ff3: eth1:
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:ff4: bond0:
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: upMII Polling Interval (ms): 100Up Delay (ms): 0Down Delay (ms): 0Slave Interface: eth0MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 00:0c:29:8b:16:7fSlave queue ID: 0Slave Interface: eth1MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 00:0c:29:8b:16:89Slave 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: upMII Polling Interval (ms): 100Up Delay (ms): 0Down Delay (ms): 0Slave Interface: eth0MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 00:0c:29:8b:16:7fSlave queue ID: 0Slave Interface: eth1MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 00:0c:29:8b:16:89Slave queue ID: 0

  查看ping

[root@mast ~]# ping 192.168.10.37PING 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 ms64 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 ms64 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 ms64 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-eth0DEVICE=eth0TYPE=EthernetUUID=985636c1-f56c-40fb-b4c0-ff18e376fb22ONBOOT=yesNM_CONTROLLED=yesBOOTPROTO=noneHWADDR=00:0C:29:8B:16:7FIPADDR=192.168.10.36PREFIX=24GATEWAY=192.168.10.2DNS1=8.8.8.8DEFROUTE=yesIPV4_FAILURE_FATAL=yesIPV6INIT=noNAME="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 bondbonding               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 ~]#  hostnamechenxi

  查看网卡配置文件链接

[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=EthernetPROXY_METHOD=noneBROWSER_ONLY=noBOOTPROTO=noneDEFROUTE=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=yesIPV6_FAILURE_FATAL=noIPV6_ADDR_GEN_MODE=stable-privacyNAME=chenxi-1UUID=36fb46d4-3306-4f65-be1d-90d26e6c82b2DEVICE=ens33ONBOOT=yesIPADDR=192.168.10.40PREFIX=24GATEWAY=192.168.10.2DNS1=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 a1: lo: 
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 forever2: ens33:
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 forever3: ens37:
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 a1: lo: 
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 forever2: ens33:
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 forever3: ens37:
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 forever4: br0:
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 a1: lo:
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 forever2: ens33:
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:ff3: ens37:
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:ff4: br0:
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

  

 

转载于:https://www.cnblogs.com/rdchenxi/p/10546054.html

你可能感兴趣的文章
格而知之2:UIView的autoresizingMask属性探究
查看>>
我的Hook学习笔记
查看>>
js中的try/catch
查看>>
寄Android开发Gradle你需要知道的知识
查看>>
整理推荐的CSS属性书写顺序
查看>>
css & input type & search icon
查看>>
C# 强制关闭当前程序进程(完全Kill掉不留痕迹)
查看>>
ssm框架之将数据库的数据导入导出为excel文件
查看>>
语音识别中的MFCC的提取原理和MATLAB实现
查看>>
0320-学习进度条
查看>>
MetaWeblog API Test
查看>>
移动、尺寸改变
查看>>
c# 文件笔记
查看>>
类和结构
查看>>
CSS3选择器(二)之属性选择器
查看>>
adidas crazylight 2018 performance analysis review
查看>>
typeset shell 用法
查看>>
python 之 循环语句
查看>>
心得25--JDK新特性9-泛型1-加深介绍
查看>>
[转]ceph网络通信模块_以monitor模块为例
查看>>