LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 08-14-2012, 08:19 AM   #1
sopel1000
LQ Newbie
 
Registered: Aug 2012
Posts: 7

Rep: Reputation: Disabled
Two IP addresses on 1 host (1 for host and one for guest)


Hi,

I have a problem with setting up a working environment with a following configuration:

1 host OS on a dedicated server (Ubuntu, it's already working). It has an IP address XX.XXX.YY.YY with a mask of: 255.255.255.252 and the operator has assigned a second IP address: XX.XXX.YZ.VW, mask: 255.255.255.255

Gateway is the same of course.

I want to assign the second ip address to a VirtualBox VM. I have no idea how to do that, could you please help?
 
Old 08-14-2012, 12:49 PM   #2
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,669

Rep: Reputation: 498Reputation: 498Reputation: 498Reputation: 498Reputation: 498
Open a terminal and read these:

Quote:
--$ man route
and

Quote:
--$ man ifconfig
Good luck and enjoy.
 
Old 08-14-2012, 01:11 PM   #3
sopel1000
LQ Newbie
 
Registered: Aug 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
But the thing is: what do I set on VirtualBox? Do I set the new IP and enable bridging? Or Do I set host-guest communication only, or NAT or what?

I have tried it, but it causes so many problems that I thought it might be wise to ask..
 
Old 08-14-2012, 10:32 PM   #4
KinnowGrower
Member
 
Registered: May 2008
Location: Toronto
Distribution: Centos && Debian
Posts: 347

Rep: Reputation: 34
Did you tried NAT.?. As for as I know, Virtual box by default assign IP address using DHCP in range of 10.xx.xx.xx. With NAT your guest OS should work fine.
 
Old 08-15-2012, 03:54 AM   #5
r0b0
Member
 
Registered: Aug 2004
Location: Europe
Posts: 608

Rep: Reputation: 50
Hi,

We have a similar situation here - additional IP addresses with netmask /32 assigned by ISP. You need to bridge the VM in virtual box. Then in your VM, put something like this in your /etc/network/interfaces:

Code:
auto eth0
iface eth0 inet static
        address XX.XXX.YZ.VW
        netmask 255.255.255.255
        post-up ip route add XX.XXX.YY.YQ/255.255.255.252 dev eth0; route add default gw XX.XXX.YY.YP eth0
Where XX.XXX.YY.YP is the default gateway IP and XX.XXX.YY.YQ/255.255.255.252 is the network.
 
Old 08-16-2012, 09:14 AM   #6
sopel1000
LQ Newbie
 
Registered: Aug 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi,

I tried what you wrote. In the configuration you wrote, there is absolutely nothing to configure on the host, only in the VM? If that is the case, then it's not working for me. I did apply what you wrote, but have not tampered with ifconfig on the host - it has it's first IP address. Doesn't work.

Regards!
 
Old 08-16-2012, 10:07 AM   #7
sopel1000
LQ Newbie
 
Registered: Aug 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Basically, I am using virtualbox on my other dedicated server but there I have no problems at all -> because one of the providers allows me to use DHCP, so I bridge my VBox interfaces and if I have several of them, I get different IP's for different MAC addresses.

Unfortunately now I have to cope with different provider... So, to sum up:

First ip address I have (for the host):
Code:
IP: XX.XXX.Z4.42
Mask: 255.255.255.252
GW: XX.XXX.Z4.41
Second IP I got (which I need assign for a guest OS running on VirtualBox):
Code:
IP: XX.XXX.Z3.61
Mask: 255.255.255.255 (mask: /32!)
GW: XX.XXX.Z4.41
Gateways are the same. As I was instructed by r0b0, I changed config on the guest OS (inside VM) and set VM into bridging.

Code:
auto eth0
iface eth0 inet static
        address XX.XXX.Z3.61
        netmask 255.255.255.255
        post-up ip route add XX.XXX.Z4.40/255.255.255.252 dev eth0; route add default gw XX.XXX.Z4.41 eth0
After doing that, if I ping from the host os, I get:

Code:
 From XX.XXX.Z4.41: icmp_seq=1 Redirect Host(New nexthop: XX.XXX.Z4.42)
How to finally get it done? I'm fed up!
 
Old 08-16-2012, 11:54 AM   #8
sopel1000
LQ Newbie
 
Registered: Aug 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
I have just received the e-mail from my provider:

"You have to create a virtual interface, we are routing IP to the main IP of your server: XX.XXX.Z4.42.
You have to resign from bridging because it is not going to work."

So, what do I do? How do I route it to vboxnet0?
 
Old 08-16-2012, 05:39 PM   #9
sopel1000
LQ Newbie
 
Registered: Aug 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
What if I used DNAT and SNAT? I read it would be a good idea, but I have no bloody idea how to do that...
 
Old 08-22-2012, 07:17 AM   #10
r0b0
Member
 
Registered: Aug 2004
Location: Europe
Posts: 608

Rep: Reputation: 50
If .41 is refusing to route packets coming from .61, maybe you can route them through .42. To make that work, allow IP forwarding, FORWARD iptables chain and set static route on .42 and set default gateway on .61 to .42 instead of .41:

Code:
# on .42:
echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -A FORWARD -s XX.XXX.Z3.61 -j ACCEPT
iptables -A FORWARD -d XX.XXX.Z3.61 -j ACCEPT
ip route add XX.XXX.Z3.61/255.255.255.255 dev eth0

# on .61:
auto eth0
iface eth0 inet static
        address XX.XXX.Z3.61
        netmask 255.255.255.255
        post-up ip route add XX.XXX.Z4.40/255.255.255.252 dev eth0; route add default gw XX.XXX.Z4.42 eth0
Let's see if this works...
 
Old 08-29-2012, 10:52 AM   #11
sopel1000
LQ Newbie
 
Registered: Aug 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
So, basically I have vboxnet0 interface with 192.168.56.1 on host machine. Virtualbox is in host-only mode. Virtualbox has 192.168.56.101 IP address assigned.

What I did and that seems to be working fine:

Code:
sudo iptables -t nat -I PREROUTING -d NEW_IP -j DNAT --to-destination 192.168.56.101
sudo iptables -t nat -I POSTROUTING -s 192.168.56.101 -j SNAT --to NEW_IP
sudo iptables -I FORWARD -d NEW_IP -j ACCEPT
sudo iptables -I FORWARD -d 192.168.56.101 -j ACCEPT
Thanks to that, the 192.168.56.101 address is available outside as NEW_IP. Thanks for your help!
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Guest to Host message passing - guest's memory usage statistics & guest's IP address Prince_Pangeni Linux - Virtualization and Cloud 2 03-03-2012 03:06 AM
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
Forwarding ping packets from one 1st host to 2nd host via 2rd host sachee Linux - Networking 1 09-25-2011 01:51 PM
host only networking for "Crunchbang host" "Arch Linux guest" ted9411 Linux - Virtualization and Cloud 3 06-06-2011 08:29 AM
VirtualBox: Slackware64 host and guest; NFS mount from host fails catkin Linux - Virtualization and Cloud 0 11-15-2010 06:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 07:45 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