linux系统怎么创建桥接模式的网卡
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux系统怎么创建桥接模式的网卡相关的知识,希望对你有一定的参考价值。
参考技术A 使用桥接上网的话需要配置linux系统的IP,具体步骤如下: 1,在命令行模式下或者桌面上进入终端模式,找到/etc/sysconfig/network-script/ifcfg-eth0文件; 2,使用vi打开文件 vi ifcfg-eth0,注意,有的linux系统这个文件可能不带ifcfg前缀。本回答被提问者采纳Linux创建桥接网络
一、图形化创建
#nm-connection-editor &
选择桥接
设置桥接网络
点击添加
模式选择以太网
添加上行网卡
# brctl show
删除桥接
# nmcli connection delete Br0
# nmcli connection delete Br0_1
#ip a
二、命令行添加
# nmcli connection add type bridge con-name br0 ifname br0
# nmcli connection modify br0 ipv4.addresses "192.168.100.26/24"
# nmcli connection modify br0 ipv4.gateway 192.168.100.2
# nmcli connection modify br0 ipv4.dns 8.8.8.8
# nmcli connection modify br0 ipv4.method manual
# nmcli connection add type bridge-slave con-name br0_1 ifname eno33554960 master br0
三、修改网络配置文件创建桥接网络(推荐使用此方法)
备份原网卡配置文件
# cd /etc/sysconfig/network-scripts/
# cp ifcfg-enp2s0 ifcfg-enp2s0.bak
[root@localhost images]# cd /etc/sysconfig/network-scripts/ [root@localhost network-scripts]# [root@localhost network-scripts]# ls ifcfg-br0 ifdown-bnep ifdown-isdn ifdown-Team ifup-bnep ifup-isdn ifup-routes ifup-wireless ifcfg-enp2s0 ifdown-eth ifdown-post ifdown-TeamPort ifup-eth ifup-plip ifup-sit init.ipv6-global ifcfg-enp2s0.bak ifdown-ib ifdown-ppp ifdown-tunnel ifup-ib ifup-plusb ifup-Team network-functions ifcfg-lo ifdown-ippp ifdown-routes ifup ifup-ippp ifup-post ifup-TeamPort network-functions-ipv6 ifdown ifdown-ipv6 ifdown-sit ifup-aliases ifup-ipv6 ifup-ppp ifup-tunnel [root@localhost network-scripts]#
配置网卡文件
# cat ifcfg-enp2s0
[root@localhost network-scripts]# cat ifcfg-enp2s0 TYPE=Ethernet BOOTPROTO=none DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=enp2s0 UUID=e0c33ce1-c0d7-4efc-a8b6-1c93e4193a29 DEVICE=enp2s0 ONBOOT=yes #IPADDR=192.168.2.150 #NETMASK=255.255.255.0 #GATEWAY=192.168.2.254 #DNS1=1.2.4.8 BRIDGE=br0
# cat ifcfg-br0
[root@localhost network-scripts]# cat ifcfg-br0 TYPE=Bridge BOOTPROTO=static NAME=br0 DEVICE=br0 ONBOOT=yes IPADDR=192.168.2.150 NETMASK=255.255.255.0 GATEWAY=192.168.2.254 DNS1=1.2.4.8
重启网卡
# systemctl restart network
检查当前的网络接口
# ip a
其中virbr0是由宿主机虚拟机支持模块安装时产生的虚拟网络接口,也是一个switch和bridge,负责把内容分发到各虚拟机。
[root@localhost network-scripts]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 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: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000 link/ether 88:d7:f6:c9:1f:2c brd ff:ff:ff:ff:ff:ff 3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000 link/ether 52:54:00:b8:96:cd brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever 4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000 link/ether 52:54:00:b8:96:cd brd ff:ff:ff:ff:ff:ff 7: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000 link/ether 88:d7:f6:c9:1f:2c brd ff:ff:ff:ff:ff:ff inet 192.168.2.150/24 brd 192.168.2.255 scope global br0 valid_lft forever preferred_lft forever inet6 fe80::948d:64ff:fe85:df22/64 scope link valid_lft forever preferred_lft forever
查看桥接
# brctl show
virbr0是一个桥接器,接收所有到网络192.168.122.*的内容
[root@localhost network-scripts]# brctl show bridge name bridge id STP enabled interfaces br0 8000.88d7f6c91f2c no enp2s0 virbr0 8000.525400b896cd yes virbr0-nic
查看路由表
# route
[root@localhost network-scripts]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 192.168.2.254 0.0.0.0 UG 0 0 0 br0 link-local 0.0.0.0 255.255.0.0 U 1007 0 0 br0 192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 br0 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
end
以上是关于linux系统怎么创建桥接模式的网卡的主要内容,如果未能解决你的问题,请参考以下文章