如何使用 apt-get 在 Ubuntu Linux 上安装 ssh
2024年3月29日操作方法:在 Unix/Linux 中 Bash 提取文件名和扩展名
2024年3月29日我的服务器有 5 个以太网端口和 1 个 ADSL 端口。如何使用 Debian Linux 操作系统设置 IPv4 软件桥,以便其余五个端口充当网络交换机?
教程详情 | |
---|---|
难度级别 | 中间的 |
根权限 | 是的 |
要求 | Debian Linux |
美东时间。阅读时间 | 5分钟 |
在 Debian Linux 下需要使用 brctl 命令来桥接网络连接。这对于:
- 在多个设备之间共享您的互联网连接。
- 无需购买专用网络交换机即可增加以太网插孔容量。
- 将 Debian 设置为接入点等等。
安装bridge-utils包
您需要安装一个名为bridge-utils 的软件包来配置Linux 以太网桥。
# apt-get install bridge-utils
输出示例:
读取软件包列表...完成 构建依赖关系树 读取状态信息...完成 将安装以下新软件包: bridge-utils 0 个已升级、1 个新安装、0 个要删除、0 个未升级。 需要获取 35.5 kB 的档案。 此操作后,将使用 145 kB 的额外磁盘空间。 Get:1 http://mirror.anl.gov/debian/wheezy/mainbridge-utils i386 1.5-6 [35.5 kB] 在 1 秒内获取 35.5 kB (21.9 kB/s) 选择之前未选择的包bridge-utils。 (正在读取数据库...当前安装的23737个文件和目录。) 解压bridge-utils(来自.../bridge-utils_1.5-6_i386.deb)... 处理man-db的触发器... 设置bridge-实用程序 (1.5-6) ...
配置
在下面的示例中,eth0 到 eth4 充当交换机。编辑文件/etc/network/interfaces,输入:
要使您的网桥配置永久编辑此文件。追加/修改如下:
# cp -v /etc/network/{interfaces,interfaces.bak}
# vi /etc/network/interfaces
# 环回网络接口 auto lo iface lo inet Loopback # Eth0 到 Eth5 网络交换机 allowed-hotplug eth0 iface eth0 inet Manual pre-up ifconfig $IFACE up pre-down ifconfig $IFACE down allowed-hotplug eth1 iface eth1 inet Manual pre-up ifconfig $IFACE up pre-down ifconfig $IFACE down allowed-hotplug eth2 iface eth2 inet 手动预启动 ifconfig $IFACE up pre-down ifconfig $IFACE down allowed-hotplug eth3 iface eth3 inet 手动预 启动 ifconfig $IFACE up pre- down ifconfig $IFACE down allowed-hotplug eth4 iface eth4 inet Manual pre-up ifconfig $IFACE up pre-down ifconfig $IFACE down # 为网桥设置 IP 地址 auto br0 iface br0 inet staticbridge_ports eth0 eth1 eth2 eth3 eth4 地址 192.168。 1.253 广播 192.168.1.255 网络掩码 255.255.255.0
保存并关闭文件。
重新启动网络服务
要停止当前网络配置,请输入:
# service networking stop
示例输出:
取消配置网络接口...完成。
要激活 br0 网络接口,请输入:
# service networking start
示例输出:
配置网络接口... 等待 br0 准备就绪(MAXWAIT 为 32 秒)。 完毕。
验证 br0 配置
键入以下命令:
# ip addr show
示例输出:
1: 瞧:mtu 16436 qdisc noqueue 状态未知 链接/环回 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 范围主机 lo inet6 ::1/128 范围主机 valid_lft永远首选_lft永远 2:eth0: mtu 1500 qdisc pfifo_fast 主 br0 状态 UP qlen 1000 链路/以太 00:00:24:cf:69:68 brd ff:ff:ff:ff:ff:ff 3: eth1: mtu 1500 qdisc pfifo_fast 主 br0 状态未知 qlen 1000 链路/以太 00:05:b4:09:ee:9c brd ff:ff:ff:ff:ff:ff 4: eth2: mtu 1500 qdisc pfifo_fast 主 br0 状态 DOWN qlen 1000 链路/以太 00:00:24:cf:69:69 brd ff:ff:ff:ff:ff:ff 5: eth3: mtu 1500 qdisc pfifo_fast master br0 state DOWN qlen 1000 link/ether 00:00:24:cf:69:6a brd ff:ff:ff:ff:ff:ff 6: eth4: mtu 1500 qdisc pfifo_fast master br0 state DOWN qlen 1000 link/ether 00:00:24:cf:69:6b brd ff:ff:ff:ff:ff:ff 7: wlan0: mtu 1500 qdisc noop state DOWN qlen 1000 link/ether 00:1d:73:bc:e4:6e brd ff:ff:ff:ff:ff:ff 8: br0: mtu 1500 qdisc noqueue state UP link/ether 00:00:24:cf:69:68 brd ff:ff:ff:ff:ff:ff inet 192.168.1.253/24 brd 192.169.1.255 scope global br0 inet6 fe80::200:24ff:fecf:6968/64 scope link valid_lft forever preferred_lft forever
You can use the following brctl command to see all current instances of the ethernet bridge:
# brctl show
Sample outputs:
bridge name bridge id STP enabled interfaces br0 8000.000024cf6968 no eth0 eth1 eth2 eth3 eth4
How do I show a list of mac address?
# brctl showmacs br0
How can I see bridge stp information?
# brctl showstp br0
Other options
To see all other supported options type the following command
$ man brctl
OR
$ brctl --help
Sample outputs:
Usage: brctl [commands] commands: addbradd bridge delbr delete bridge addif add interface to bridge delif delete interface from bridge hairpin {on|off} turn hairpin on/off setageing
A note about DHCPD server
You may want to setup DHCPD server to allow clients such as desktop, laptop, and mobile devices to request and obtain an IP address and many other parameters from a server / switch itself. See how to setup an ISC DHCP Server for your network for more information.
A note about Iptables
数据会流经所有接口,因此只需在一个接口上进行过滤即可。使用 Linux 内核和 iptables (NAT) 打开数据包转发。假设 eth6 或 ppp0 是连接互联网的。首先,在内核中打开 IP 转发:
# sysctl -w net.ipv4.ip_forward=1
接下来,使用以下命令:
或设置 IP 转发和伪装 (NAT):
随意根据您的设置修改规则。有关更多信息,请参阅 iptables 手册页或以下教程:
/sbin/iptables -t nat -A POSTROUTING -o eth6 -j MASQUERADE
### ppp0 ###
/sbin/iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
/sbin/iptables --table nat --append POSTROUTING --out-interface eth6 -j MASQUERADE
/sbin/iptables --append FORWARD --in-interface br0 -j ACCEPT
- Debian / Ubuntu Linux:安装和配置海岸线防火墙(Shorewall)
- Linux:针对新系统管理员的 20 个 Iptables 示例
也可以看看
- KVM Guest:与主机共享物理网络设备(桥接配置)
- Debian Linux:将网络接口配置为网桥/网络交换机
- OpenBSD:将网络接口配置为网桥/网络交换机
- 如何将 PFSense 配置网络接口作为网桥/网络交换机
- FreeBSD:NIC 绑定/链路聚合/中继/链路故障转移
- 如何在 Ubuntu Linux 14.04 和 16.04 LTS 上设置桥接 (br0) 网络
- Ubuntu 设置绑定设备并从属 eth0+eth2
- 在 Ubuntu 上设置绑定 (bond0) 和桥接 (br0) 网络
- Ubuntu 20.04 使用 nmcli 命令添加网桥(br0)
- CentOS 8 使用 nmcli 命令添加网桥(br0)
- 如何在Linux上使用nmcli(NetworkManager)添加网桥
- 在 Debian Linux 上设置和配置网桥