我建議以下方法:
- 確保橋接接口是向下
- 配置橋接接口
- 執行
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