|
|
|
|
|
|
|
|
|
|
xen-users
Re: [xen-users] two networks with two networking cards...?
here's how i try to did:
-------------------------------
Dom0 : eth0 --> ip 192.168.1.10
gw 192.168.1.1
eth1 --> ip 192.168.2.20
gw 192.168.2.1
i'd like to have the the host (Dom0) using the eth0 interface with
192.168.1.10 gw 192.168.1.1
and i'd like to have ONE guest (DomU) using the eth1 interface with
192.168.2.200 gw 192.168.2.1
-----------------------------------------------------------------------------------------------------------------------------------------------
on Dom0:
cat /etc/xen/xend-config.sxp
(network-script network-bond-bridge-setup)
(vif-script vif-bridge)
(dom0-min-mem 196)
(dom0-cpus 0)
------
cat /etc/network/interfaces
auto lo
iface lo inet loopback
auto xenbr0
iface xenbr0 inet static
address 192.168.1.10
netmask 255.255.255.0
network 192.168.1.0
broadcast 172.20.22.255
gateway 192.168.1.1
bridge_ports eth0
# optional
bridge_maxwait 0
auto xenbr1
iface xenbr1 inet static
address 192.168.2.20
netmask 255.255.255.0
network 192.168.1.0
broadcast 172.20.10.255
gateway 192.168.2.1
bridge_ports eth1
# optional
bridge_maxwait 0
------------------
cat /etc/xen/scripts/network-bond-bridge-setup
#!/bin/sh
# 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/
s@\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+/[0-9]\+\)@\1@
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
}
# Usage: create_bridge bridge
create_bridge () {
local bridge=$1
# Don't create the bridge if it already exists.
if ! brctl show | grep -q ${bridge} ; then
brctl addbr ${bridge}
brctl stp ${bridge} off
brctl setfd ${bridge} 0
fi
ip link set ${bridge} up
}
# Usage: add_to_bridge bridge dev
add_to_bridge () {
local bridge=$1
local dev=$2
# Don't add $dev to $bridge if it's already on a bridge.
if ! brctl show | grep -q ${dev} ; then
brctl addif ${bridge} ${dev}
fi
}
# Usage: show_status dev bridge
# Print ifconfig and routes.
show_status () {
local dev=$1
local bridge=$2
echo '============================================================'
ip addr show ${dev}
ip addr show ${bridge}
echo ' '
brctl show ${bridge}
echo ' '
ip route list
echo ' '
route -n
echo '============================================================'
}
op_start () {
create_bridge xenbr0
#add_to_bridge xenbr0 vif0.0
add_to_bridge2 xenbr0 eth0
#transfer_addrs bond0 xenbr0
#transfer_routes bond0 xenbr0
create_bridge xenbr1
add_to_bridge xenbr1 eth2
ifconfig xenbr1 172.20.0.190 netmask 255.255.255.0 up
route add default gw 172.20.0.1
create_bridge xenbr2
create_bridge xenbr3
}
op_stop () {
transfer_routes xenbr0 eth0
ip link set xenbr0 down
brctl delbr xenbr0
ip link set xenbr1 down
brctl delbr xenbr1
}
# adds $dev to $bridge but waits for $dev to be in running state first
add_to_bridge2() {
local bridge=$1
local dev=$2
local maxtries=10
echo -n "Waiting for ${dev} to negotiate link."
for i in `seq ${maxtries}` ; do
if ifconfig ${dev} | grep -q RUNNING ; then
break
else
echo -n '.'
sleep 1
fi
done
if [ ${i} -eq ${maxtries} ] ; then echo '(link isnt in running state)' ; fi
add_to_bridge ${bridge} ${dev}
}
case "${1}" in
start)
op_start
;;
stop)
op_stop
;;
status)
show_status ${netdev} ${bridge}
;;
*)
echo "Unknown command: ${1}" >&2
echo 'Valid commands are: start, stop, status' >&2
exit 1
esac
------------------------------------------------------------------------------------------------------------
on DomU
cat /etc/xen/test0.cfg
#
# Networking
#
vif = [ 'ip=192.168.2.200' ]
------------------------
cat /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.2.200
gateway 192.168.2.1
netmask 255.255.255.0
##########################################################################
what's i get:
# brctl show
bridge name bridge id STP enabled interfaces
xenbr0 8000.000ffe6df4e5 no eth0
vif2.0
xenbr1 8000.0013f70ba95c no eth1
----------
eth0 Link encap:Ethernet HWaddr 00:0F:FE:6D:F4:E5
inet6 addr: fe80::20f:feff:fe6d:f4e5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:12594 errors:0 dropped:0 overruns:0 frame:0
TX packets:1207 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:2212135 (2.1 MiB) TX bytes:173429 (169.3 KiB)
Base address:0x2100 Memory:f0500000-f0520000
eth1 Link encap:Ethernet HWaddr 00:13:F7:0B:A9:5C
inet6 addr: fe80::213:f7ff:fe0b:a95c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:25128 errors:0 dropped:0 overruns:0 frame:0
TX packets:69 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9397421 (8.9 MiB) TX bytes:5273 (5.1 KiB)
Interrupt:19 Base address:0xa000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:840 (840.0 b) TX bytes:840 (840.0 b)
vif2.0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
RX packets:235 errors:0 dropped:0 overruns:0 frame:0
TX packets:10049 errors:0 dropped:1 overruns:0 carrier:0
collisions:0 txqueuelen:32
RX bytes:13703 (13.3 KiB) TX bytes:1830178 (1.7 MiB)
xenbr0 Link encap:Ethernet HWaddr 00:0F:FE:6D:F4:E5
inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20f:feff:fe6d:f4e5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:12148 errors:0 dropped:0 overruns:0 frame:0
TX packets:978 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1939726 (1.8 MiB) TX bytes:151682 (148.1 KiB)
xenbr1 Link encap:Ethernet HWaddr 00:13:F7:0B:A9:5C
inet addr:192.168.2.20 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::213:f7ff:fe0b:a95c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:24921 errors:0 dropped:0 overruns:0 frame:0
TX packets:69 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:8910868 (8.4 MiB) TX bytes:5015 (4.8 KiB)
--------------------
the problem is that the Dom0 is using the address of eth1 interface:
192.168.2.20.
i'd like it use the the eth0 interface 192.168.1.10.
i can ping work-bond-bridge-setup)
(vif-script vif-bridge)
(dom0-min-mem 196)
(dom0-cpus 0)
------
cat /etc/network/interfaces
auto lo
iface lo inet loopback
auto xenbr0
iface xenbr0 inet static
address 192.168.1.10
netmask 255.255.255.0
network 192.168.1.0
broadcast 172.20.22.255
gateway 192.168.1.1
bridge_ports eth0
# optional
bridge_maxwait 0
auto xenbr1
iface xenbr1 inet static
address 192.168.2.20
netmask 255.255.255.0
network 192.168.1.0
broadcast 172.20.10.255
gateway 192.168.2.1
bridge_ports eth1
# optional
bridge_maxwait 0
------------------
cat /etc/xen/scripts/network-bond-bridge-setup
#!/bin/sh
# 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/
s@\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+/[0-9]\+\)@\1@
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
}
# Usage: create_bridge bridge
create_bridge () {
local bridge=$1
# Don't create the bridge if it already exists.
if ! brctl show | grep -q ${bridge} ; then
brctl addbr ${bridge}
brctl stp ${bridge} off
brctl setfd ${bridge} 0
fi
ip link set ${bridge} up
}
# Usage: add_to_bridge bridge dev
add_to_bridge () {
local bridge=$1
local dev=$2
# Don't add $dev to $bridge if it's already on a bridge.
if ! brctl show | grep -q ${dev} ; then
brctl addif ${bridge} ${dev}
fi
}
# Usage: show_status dev bridge
# Print ifconfig and routes.
show_status () {
local dev=$1
local bridge=$2
echo '============================================================'
ip addr show ${dev}
ip addr show ${bridge}
echo ' '
brctl show ${bridge}
echo ' '
ip route list
echo ' '
route -n
echo '============================================================'
}
op_start () {
create_bridge xenbr0
#add_to_bridge xenbr0 vif0.0
add_to_bridge2 xenbr0 eth0
#transfer_addrs bond0 xenbr0
#transfer_routes bond0 xenbr0
create_bridge xenbr1
add_to_bridge xenbr1 eth2
ifconfig xenbr1 172.20.0.190 netmask 255.255.255.0 up
route add default gw 172.20.0.1
create_bridge xenbr2
create_bridge xenbr3
}
op_stop () {
transfer_routes xenbr0 eth0
ip link set xenbr0 down
brctl delbr xenbr0
ip link set xenbr1 down
brctl delbr xenbr1
}
# adds $dev to $bridge but waits for $dev to be in running state first
add_to_bridge2() {
local bridge=$1
local dev=$2
local maxtries=10
echo -n "Waiting for ${dev} to negotiate link."
for i in `seq ${maxtries}` ; do
if ifconfig ${dev} | grep -q RUNNING ; then
break
else
echo -n '.'
sleep 1
fi
done
if [ ${i} -eq ${maxtries} ] ; then echo '(link isnt in running state)' ; fi
add_to_bridge ${bridge} ${dev}
}
case "${1}" in
start)
op_start
;;
stop)
op_stop
;;
status)
show_status ${netdev} ${bridge}
;;
*)
echo "Unknown command: ${1}" >&2
echo 'Valid commands are: start, stop, status' >&2
exit 1
esac
------------------------------------------------------------------------------------------------------------
on DomU
cat /etc/xen/test0.cfg
#
# Networking
#
vif = [ 'ip=192.168.2.200' ]
------------------------
cat /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.2.200
gateway 192.168.2.1
netmask 255.255.255.0
##########################################################################
what's i get:
# brctl show
bridge name bridge id STP enabled interfaces
xenbr0 8000.000ffe6df4e5 no eth0
vif2.0
xenbr1 8000.0013f70ba95c no eth1
----------
eth0 Link encap:Ethernet HWaddr 00:0F:FE:6D:F4:E5
inet6 addr: fe80::20f:feff:fe6d:f4e5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:12594 errors:0 dropped:0 overruns:0 frame:0
TX packets:1207 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:2212135 (2.1 MiB) TX bytes:173429 (169.3 KiB)
Base address:0x2100 Memory:f0500000-f0520000
eth1 Link encap:Ethernet HWaddr 00:13:F7:0B:A9:5C
inet6 addr: fe80::213:f7ff:fe0b:a95c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:25128 errors:0 dropped:0 overruns:0 frame:0
TX packets:69 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9397421 (8.9 MiB) TX bytes:5273 (5.1 KiB)
Interrupt:19 Base address:0xa000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:840 (840.0 b) TX bytes:840 (840.0 b)
vif2.0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
RX packets:235 errors:0 dropped:0 overruns:0 frame:0
TX packets:10049 errors:0 dropped:1 overruns:0 carrier:0
collisions:0 txqueuelen:32
RX bytes:13703 (13.3 KiB) TX bytes:1830178 (1.7 MiB)
xenbr0 Link encap:Ethernet HWaddr 00:0F:FE:6D:F4:E5
inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20f:feff:fe6d:f4e5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:12148 errors:0 dropped:0 overruns:0 frame:0
TX packets:978 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1939726 (1.8 MiB) TX bytes:151682 (148.1 KiB)
xenbr1 Link encap:Ethernet HWaddr 00:13:F7:0B:A9:5C
inet addr:192.168.2.20 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::213:f7ff:fe0b:a95c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:24921 errors:0 dropped:0 overruns:0 frame:0
TX packets:69 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:8910868 (8.4 MiB) TX bytes:5015 (4.8 KiB)
--------------------
the problem is that the Dom0 is using the address of eth0 interface:
192.168.1.10.
i'd like it use the the eth0 interface 192.168.2.20.
i can ping 192.168.1.10, 192.168.2.20
my DomU, test0 is using 192.168.2.200 gw 192.168.2.200 gw 192.168.2.1
and it works fine.
what could you suggest, please?
the script, i get it from someone.
is the config correct?
thank you in adavance.
_______________________________________________
Xen-users mailing list
Xen-users@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-users
|
|
|
|
|