LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud
User Name
Password
Linux - Virtualization and Cloud This forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.

Notices


Reply
  Search this Thread
Old 10-29-2015, 06:50 AM   #1
hortageno
Member
 
Registered: Aug 2015
Distribution: Ubuntu 22.04 LTS
Posts: 240

Rep: Reputation: 67
virtualbox guest cannot access the host's LAN with host-only adapter


Hi all,

I'm trying to setup an Ubuntu guest on an Ubuntu host so that the guest can reach the host's network, but nothing else.

Code:
guest network:    192.168.56.0/24
guest ip eth0:    192.168.56.101
host network:     192.168.99.0/24
host ip p2p1:     192.168.99.4
host ip vboxnet0: 192.168.56.1
This is what i did so far which doesn't work:

On the guest i added a route for the host's network

Code:
#route add -net 192.168.99.0 gw 192.168.56.1 netmask 255.255.255.0 dev eth0
#route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.56.0    *               255.255.255.0   U     1      0        0 eth0
192.168.99.0    192.168.56.1    255.255.255.0   UG    0      0        0 eth0
This seems to work and I can ping the host's ip 192.168.99.4

Now I enabled ipforwarding on the host with

Code:
echo 1 > /proc/sys/net/ipv4/ip_forward
and it seems to be activated for all interfaces

Code:
cat /proc/sys/net/ipv4/conf/*/forwarding
1
1
1
1
1
but I cannot reach any other pc in the 192.168.99.0 network. There is no firewall set up.

Code:
iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
Is there anything else I forgot to do?
 
Old 10-29-2015, 10:03 AM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Could you clarify your ultimate goals here? You want the guest to be able to access everything on the host's LAN, but "nothing else"? What do you mean by "nothing else"? Is there another LAN the host can access that you don't want the guest to, or are you talking about the outside internet? Does it matter where the restriction is coming from? In other words, does the host need to restrict the guest's access to the network, or is it alright if the guest restricts itself?
 
1 members found this post helpful.
Old 10-29-2015, 11:34 AM   #3
hortageno
Member
 
Registered: Aug 2015
Distribution: Ubuntu 22.04 LTS
Posts: 240

Original Poster
Rep: Reputation: 67
Quote:
Originally Posted by suicidaleggroll View Post
Could you clarify your ultimate goals here? You want the guest to be able to access everything on the host's LAN, but "nothing else"? What do you mean by "nothing else"? Is there another LAN the host can access that you don't want the guest to, or are you talking about the outside internet? Does it matter where the restriction is coming from? In other words, does the host need to restrict the guest's access to the network, or is it alright if the guest restricts itself?
With "nothing else" I meant the outside Internet.

I think I know where you coming from. I guess I could use the bridged network adapter and define a default non-existing gateway or delete the default route altogether.

I just tried it out and it works. But what if I still need the VM to be in its own network and also to learn something. Why does the ipforwarding not work the way I did it?

Edit: I just found another way to do it. In the IPv4/Routes settings of the network manager there is a checkbox for "use this connection only for resources on its network". This deletes the default route.

Last edited by hortageno; 10-29-2015 at 11:41 AM.
 
Old 10-29-2015, 11:59 AM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by hortageno View Post
With "nothing else" I meant the outside Internet.

I think I know where you coming from. I guess I could use the bridged network adapter and define a default non-existing gateway or delete the default route altogether.

I just tried it out and it works.
Yes that's exactly what I was working towards, good job getting it running and I'm glad it works.

Quote:
Originally Posted by hortageno View Post
But what if I still need the VM to be in its own network and also to learn something. Why does the ipforwarding not work the way I did it?
All good questions, but I'm afraid I don't know enough about IP forwarding in Linux to answer it. Hopefully somebody else will come along who does.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Protect host (and LAN) from virtualbox guest using NAT joe_2000 Linux - Security 9 01-11-2015 11:44 AM
Access server running on localhost on host system through virtualbox guest OS Jean-Luc Besson Linux - Virtualization and Cloud 3 05-15-2012 03:19 PM
Host Fedora14, Windows 7 is running as Virtualbox guest- Mic is not working on Guest mwaheed Linux - Virtualization and Cloud 1 10-20-2011 12:51 PM
VirtualBox: Slackware64 host and guest; NFS mount from host fails catkin Linux - Virtualization and Cloud 0 11-15-2010 06:54 AM
VirtualBox Raw Access, Windows Host, Linux Guest Guitarist88 Linux - Newbie 2 11-14-2008 04:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud

All times are GMT -5. The time now is 06:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration