Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Sharing network connection with xen guest domains
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
apurkrt
Tux's lil' helper
Tux's lil' helper


Joined: 26 Feb 2011
Posts: 116
Location: Czechia, Europe

PostPosted: Sun Jan 19, 2020 9:26 pm    Post subject: Sharing network connection with xen guest domains Reply with quote

Hello!
After some effort, I have setup xen on my laptop, succesfully booted it and have running dom0.

I also created the following /etc/xen/auto/gentoo.hvm
Code:
name = 'gentoo'
builder = 'hvm'
memory = 4096
vcpus = 2
disk = [ 'phy:/dev/vg0/gentooxen,xvda,w', 'file:/home/adam/Downloads/iso/install-amd64-minimal-20191229T214502Z.iso,hdc:cdrom,r' ]
vif = [ 'bridge=xenbr0' ]
boot = 'dc'
vnc = 1
vnclisten = '127.0.0.1'
vncdisplay = 1
serial = 'pty'


there is /etc/conf.d/net containing
Code:
# Bridge dynamic config
config_xenbr0="dhcp"


When I run
Code:
gentoo ~ # ip link add xenbr0 type bridge
gentoo ~ # ip link set dev enp1s0 master xenbr0
gentoo ~ # ip link set xenbr0 up
gentoo ~ # xl create /etc/xen/auto/gentoo.hvm


the virtual machine successfully boots up (I see it with remmina vnc on localhost:5901), and the network in it is working -but- I lose network connection on the host machine (i.e. in dom0).

Would somebody know of a setup that would make the network accessible from the guest domain, while keeping it also working for the host machine (dom0)?
Also I would like to be able to ssh from the host to the guest.

EDIT: changed gentoo.cfg to gentoo.hvm, added boot='dc' to the gentoo.hvm (for easier bootup from the iso), changed vnclisten to '127.0.0.1'


Last edited by apurkrt on Mon Jan 27, 2020 9:27 am; edited 2 times in total
Back to top
View user's profile Send private message
apurkrt
Tux's lil' helper
Tux's lil' helper


Joined: 26 Feb 2011
Posts: 116
Location: Czechia, Europe

PostPosted: Wed Jan 22, 2020 8:15 pm    Post subject: Reply with quote

The setup procedure that worked for me is as follows (kudos to colleagues irl and on irc)

0) I have net-misc/dhcpcd installed
1) remove netmount from the default runlevel (to prevent running dhcpcd on all interfaces)
Code:
# rc-update delete netmount

2) /etc/conf.d/net has the following content:
Code:
bridge_xenbr0="enp1s0"
config_xenbr0="dhcp"
config_enp1s0="null"

3) I also did the following:
Code:
# cd /etc/init.d
# ln -s net.lo net.xenbr0
# rc-update add net.xenbr0 default


After reboot, I can use the network in dom0 as usual; there is network available in domU (hvm gentoo). I can ssh from dom0 to domU.
Back to top
View user's profile Send private message
apurkrt
Tux's lil' helper
Tux's lil' helper


Joined: 26 Feb 2011
Posts: 116
Location: Czechia, Europe

PostPosted: Sun May 10, 2020 7:01 am    Post subject: Reply with quote

Ha, finally! I've found today how to start the bridged network up automatically whenever the cable is plugged in.
Since config_xenbr0="dhcp" would cause prolonged lockup on start, if the cable was not connected, I had it set up to "null" for some time now, and used "dhcpcd xenbr0" manually when I knew the cable is plugged. It worked, but it was somehow tedious.

The solution: use properly configured net-misc/dhcpcd - emphasis on "properly configured".
(I have the xen setup on a laptop - on a server, statically assigned IP might be a better choice)

I've actually tried dhcpcd already some time ago. But it would always assign the ip directly to enp1s0, and not to xenbr0, which was not what I wanted. Then I've tried ifplugd and netplug, fiddled around with /etc/conf.d/net a lot - only to find out neither of them work with network bridges.

Today it finally stroke me: it should be possible to configure dhcpcd to watch only xenbr0 (and also wireless), and somehow disable autodetection on enp1s0. And it is indeed possible.

1) /etc/conf.d/net contains
Code:

config_enp1s0="null"
config_xenbr0="null"
bridge_xenbr0="enp1s0"

i.e. I have changed the config_xenbr0 from "dhcp" to "null"
2) service "net.xenbr0" (a link to net.lo in /etc/init.d) is in the default runlevel
3) added the following two lines to /etc/dhcpcd.conf:
Code:
allowinterfaces wlp2s0 xenbr0
denyinterfaces enp1s0

4) added dhcpcd to the default runlevel
Code:
rc-update add dhcpcd default


and woohoo - the startup of the machine is now fast even if the ethernet is unplugged, and the network config is acquired as soon as the cable is plugged in.

Just wanted to share this.
Back to top
View user's profile Send private message
apurkrt
Tux's lil' helper
Tux's lil' helper


Joined: 26 Feb 2011
Posts: 116
Location: Czechia, Europe

PostPosted: Wed May 13, 2020 4:45 am    Post subject: Reply with quote

Unfortunately, after three days of usage, I have found that starting "dhcpcd" in the default runlevel is not the same as starting it manually from command line after system start with "dhcpcd xenbr0", which I used to do successfully for a long time (in conjunction with config_xenbr0="null" in /etc/conf.d/net).
Somehow - I do not know how, but it is a reality - somehow, the connecting to servers takes longer when "dhcpcd" is started without any interface specified.
EDIT: Worse yet, when connected over ssh to a server, for some reason the connection "freezes" for a couple of seconds after a minute or so of inactivity. It eventually "unfreezes" (after 5 seconds or so) and is responsive again. Still a major issue.
I've found on the man page "When dhcpcd not limited to one interface on the command line, it is running in Master mode.".
So this "Master mode" somehow does not work as well as the other mode (starting dhcpcd for individual interface/bridge as "dhcpcd xenbr0"), which I used for couple of months without any issues.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum