如何在Debian Linux上设置和配置网桥

系统 Linux 系统运维
我是一个新 Debian Linux 用户,我想为 Debian Linux 上运行的虚拟化环境(KVM)设置网桥。那么我该如何在 Debian Linux 9.x 服务器上的 /etc/network/interfaces 中设置桥接网络呢?

[[224350]]

Q:我是一个新 Debian Linux 用户,我想为 Debian Linux 上运行的虚拟化环境(KVM)设置网桥。那么我该如何在 Debian Linux 9.x 服务器上的 /etc/network/interfaces 中设置桥接网络呢?

如何你想为你的虚拟机分配 IP 地址并使其可从你的局域网访问,则需要设置网络桥接器。默认情况下,虚拟机使用 KVM 创建的专用网桥。但你需要手动设置接口,避免与网络管理员发生冲突。 

怎样安装 brctl

输入以下 apt-get 命令

  1. $ sudo apt install bridge-utils 

怎样在 Debian Linux 上设置网桥

你需要编辑 /etc/network/interface 文件。不过,我建议在 /etc/network/interface.d/ 目录下放置一个全新的配置。在 Debian Linux 配置网桥的过程如下: 

步骤 1 - 找出你的物理接口

使用 ip 命令

  1. $ ip -f inet a s

示例输出如下:

  1. 2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
  2. inet 192.168.2.23/24 brd 192.168.2.255 scope global eno1
  3. valid_lft forever preferred_lft forever

eno1 是我的物理网卡。 

步骤 2 - 更新 /etc/network/interface 文件

确保只有 lo(loopback 在 /etc/network/interface 中处于活动状态)。(LCTT 译注:loopback 指本地环回接口,也称为回送地址)删除与 eno1 相关的任何配置。这是我使用 cat 命令 打印的配置文件:

  1. $ cat /etc/network/interface
  1. # This file describes the network interfaces available on your system
  2. # and how to activate them. For more information, see interfaces(5).
  3.  
  4. source /etc/network/interfaces.d/*
  5.  
  6. # The loopback network interface
  7. auto lo
  8. iface lo inet loopback 

步骤 3 - 在 /etc/network/interfaces.d/br0 中配置网桥(br0)

使用文本编辑器创建一个文本文件,比如 vi 命令:

  1. $ sudo vi /etc/network/interfaces.d/br0

在其中添加配置:

  1. ## static ip config file for br0 ##
  2. auto br0
  3. iface br0 inet static
  4. address 192.168.2.23
  5. broadcast 192.168.2.255
  6. netmask 255.255.255.0
  7. gateway 192.168.2.254
  8. # If the resolvconf package is installed, you should not edit
  9. # the resolv.conf configuration file manually. Set name server here
  10. #dns-nameservers 192.168.2.254
  11. # If you have muliple interfaces such as eth0 and eth1
  12. # bridge_ports eth0 eth1
  13. bridge_ports eno1
  14. bridge_stp off # disable Spanning Tree Protocol
  15. bridge_waitport 0 # no delay before a port becomes available
  16. bridge_fd 0 # no forwarding delay

如果你想使用 DHCP 来获得 IP 地址:

  1. ## DHCP ip config file for br0 ##
  2. auto br0
  3.  
  4. # Bridge setup
  5. iface br0 inet dhcp
  6. bridge_ports eno1

在 vi/vim 中保存并关闭文件。 

步骤 4 - 重新启动网络服务

在重新启动网络服务之前,请确保防火墙已关闭。防火墙可能会引用较老的接口,例如 eno1。一旦服务重新启动,你必须更新 br0 接口的防火墙规则。键入以下命令重新启动防火墙:

  1. $ sudo systemctl restart network-manager

确认服务已经重新启动:

  1. $ systemctl status network-manager

借助 ip 命令寻找新的 br0 接口和路由表:

  1. $ ip a s $ ip r $ ping -c 2 cyberciti.biz

示例输出:

你可以使用 brctl 命令查看网桥有关信息:

  1. $ brctl show

显示当前网桥:

  1. $ bridge link

 

责任编辑:庞桂玉 来源: Linux中国
相关推荐

2022-12-27 08:51:31

WebDebian 11

2015-04-20 08:58:25

DHCPISC DHCP Se

2016-07-26 13:58:52

Ubuntulinux网桥

2021-10-19 06:01:24

Chrome浏览器网页浏览器

2015-12-25 14:30:47

LinuxISC DHCP服务器

2017-03-09 17:40:50

DebianUbuntuMariaDB

2022-11-01 15:49:52

2019-09-08 17:04:00

DebianLinuxAnsible

2009-04-08 15:56:31

Linux路由MAC绑定

2021-12-06 16:20:38

Flutter开发Linux

2019-08-21 14:15:47

DebianUbuntuLinux

2018-04-08 08:32:59

2021-06-30 19:42:49

LinuxOpenRazer开源

2020-05-28 08:45:21

Arch LinuxLinuxKDE Plasma

2015-11-30 15:05:01

Linux浏览器Docker

2013-03-06 13:27:03

HadoopLinux

2014-07-14 09:24:51

Debiansystemd

2018-02-26 18:00:08

Linux运维Debian

2020-12-21 20:25:24

UbuntuDebian LinuC 程序

2019-10-21 13:28:38

UbuntuPostgreSQL命令
点赞
收藏

51CTO技术栈公众号