如何在 Debian Linux 上设置和配置网桥 | Linux 中国
2018-03-29 00:00
1011 查看
那么我该如何在 Debian Linux 9.x 服务器上的 /etc/network/interfaces 中设置桥接网络呢?-- Vivek Gite
有用的原文链接请访问文末的“原文链接”获得可点击的文内链接、全尺寸原图和相关文章。
致谢编译自 | https://www.cyberciti.biz/faq/how-to-configuring-bridging-in-debian-linux/
作者 | Vivek Gite
译者 | MjSeven ? ? ? 共计翻译:16 篇 贡献时间:58 天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 命令[2]:
$ ip -f inet a s
示例输出如下:
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 192.168.2.23/24 brd 192.168.2.255 scope global eno1
valid_lft forever preferred_lft forever
eno1是我的物理网卡。步骤 2 - 更新 /etc/network/interface 文件确保只有
lo(loopback 在
/etc/network/interface中处于活动状态)。(LCTT 译注:loopback 指本地环回接口,也称为回送地址)删除与
eno1相关的任何配置。这是我使用 cat 命令[3] 打印的配置文件:
$ cat /etc/network/interface
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
步骤 3 - 在 /etc/network/interfaces.d/br0 中配置网桥(br0)使用文本编辑器创建一个文本文件,比如
vi命令:
$ sudo vi /etc/network/interfaces.d/br0
在其中添加配置:
## static ip config file for br0 ##
auto br0
iface br0 inet static
address 192.168.2.23
broadcast 192.168.2.255
netmask 255.255.255.0
gateway 192.168.2.254
# If the resolvconf package is installed, you should not edit
# the resolv.conf configuration file manually. Set name server here
#dns-nameservers 192.168.2.254
# If you have muliple interfaces such as eth0 and eth1
# bridge_ports eth0 eth1
bridge_ports eno1
bridge_stp off # disable Spanning Tree Protocol
bridge_waitport 0 # no delay before a port becomes available
bridge_fd 0 # no forwarding delay
如果你想使用 DHCP 来获得 IP 地址:
## DHCP ip config file for br0 ##
auto br0
# Bridge setup
iface br0 inet dhcp
bridge_ports eno1
在 vi/vim 中保存并关闭文件[4]。步骤 4 - 重新启动网络服务在重新启动网络服务之前,请确保防火墙已关闭。防火墙可能会引用较老的接口,例如
eno1。一旦服务重新启动,你必须更新
br0接口的防火墙规则。键入以下命令重新启动防火墙:
$ sudo systemctl restart network-manager
确认服务已经重新启动:
$ systemctl status network-manager
借助 ip 命令[2]寻找新的
br0接口和路由表:
$ ip a s $ ip r $ ping -c 2 cyberciti.biz
示例输出:
你可以使用 brctl 命令查看网桥有关信息:
$ brctl show
显示当前网桥:
$ bridge link
关于作者作者是 nixCraft 的创建者,也是经验丰富的系统管理员,DevOps 工程师以及 Linux 操作系统/ Unix shell 脚本的培训师。通过订阅 RSS/XML 流[5] 或者 每周邮件推送[6]获得关于 SysAdmin, Linux/Unix 和开源主题的最新教程。via: https://www.cyberciti.biz/faq/how-to-configuring-bridging-in-debian-linux/作者:Vivek GIte[8] 译者:MjSeven 校对:wxy本文由 LCTT 原创编译,Linux中国 荣誉推出
相关文章推荐
- Linux 有问必答:如何在 Ubuntu 上配置网桥
- 关于如何设置 Linux 的 IP配置
- [Linux]在Linux上部署Java开发环境笔记(一)-- 补充:Linux下如何手动设置IP及配置DNS服务
- 如何安装并设置 Vagrant | Linux 中国
- linux 网桥介绍以及如何配置
- 如何在 Linux 中配置 ssh 登录导语 | Linux 中国
- linux下如何配置TCP参数设置详解
- 如何在LINUX系统下修改debian wheezy默认配置的方法
- 如何在 Arch Linux 中设置日语环境 | Linux 中国
- 如何在Linux操作系统下配置双网卡路由表_当路由器设置
- 如何在 Web 服务器文档根目录上设置只读文件权限 | Linux 中国
- 循序渐进学习如何在 MariaDB 中配置主从复制 | Linux 中国
- 如何使用 cloud-init 来预配置 LXD 容器 | Linux 中国
- Linux如何设置快速的debian源
- 如何配置一个小朋友使用的 Linux | Linux 中国
- 【译】Debian Linux下如何设置与更改默认python版本
- linux 自学系列:debian 加载ssh服务、网络配置、DNS设置
- 如何在linux上配置网桥
- linux下如何配置TCP参数设置详解
- 这个地址介绍了如何配置debian linux mysql,可以进行远程访问mysql