我建议以下方法:
- 确保桥接接口是向下
- 配置桥接接口
- 执行
ifconfig eth0 down && ifconfig br0 up
,并恢复:
- 执行te
ifconfig br0 down && ifconfig eth0 up
现在的路线取决于你有什么样的路线。如果您使用显式接口定义静态路由,您唯一的选择似乎是解析ip route ls
并将它们转换为新接口。
您也可以玩弄的了&顺序围绕下命令以及多个路由表:
ip route add <whatever> table 2
ip rule add from br0 table 2
但这可能很麻烦,所以我的建议是坚持简单的解决方案,即使它包含更多的编码。
下面是xend管的network-bridge
脚本另一个例子来实现这一目标:
# Usage: transfer_addrs src dst
# Copy all IP addresses (including aliases) from device $src to device $dst.
transfer_addrs() {
local src=$1
local dst=$2
# Don't bother if $dst already has IP addresses.
if ip addr show dev ${dst} | egrep -q '^ *inet ' ; then
return
fi
# Address lines start with 'inet' and have the device in them.
# Replace 'inet' with 'ip addr add' and change the device name $src
# to 'dev $src'.
ip addr show dev ${src} | egrep '^ *inet ' | sed -e "
s/inet/ip addr add/
[email protected]\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+/[0-9]\+\)@\[email protected]
s/${src}/dev ${dst}/
" | sh -e
# Remove automatic routes on destination device
ip route list | sed -ne "
/dev ${dst}\(\|$\)/ {
s/^/ip route del/
p
}" | sh -e
}
# Usage: transfer_routes src dst
# Get all IP routes to device $src, delete them, and
# add the same routes to device $dst.
# The original routes have to be deleted, otherwise adding them
# for $dst fails (duplicate routes).
transfer_routes() {
local src=$1
local dst=$2
# List all routes and grep the ones with $src in.
# Stick 'ip route del' on the front to delete.
# Change $src to $dst and use 'ip route add' to add.
ip route list | sed -ne "
/dev ${src}\(\|$\)/ {
h
s/^/ip route del/
P
g
s/${src}/${dst}/
s/^/ip route add/
P
d
}" | sh -e
}
我喜欢你带来向上/向下的接口,以恢复路线的方法。我想这可能适用于我。现在唯一的问题是 - 如何从eth0-> br0移动路由(我相信在测试过程中两个接口都应该启动)。 – 2012-04-17 17:09:56
@AnsisAtteka你能详细阐述一下你的设置吗? br0包含哪些接口? eth0和br0在同一个物理网络上吗?你想达到什么目的? – mensi 2012-04-17 17:31:59
至少根据我的经验,在同一子网中有两个物理接口可能会很痛苦。我设法通过为接口使用单独的路由表来解决这些问题。 – mensi 2012-04-17 17:32:54