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 12-27-2010, 06:53 AM   #1
ThelenShar
LQ Newbie
 
Registered: Nov 2009
Posts: 14

Rep: Reputation: 0
Public IP routing, possible NAT guest onto host?


I have a server with 4 publicly routable IPs, and I want to put 4 VM on it and have them each with a public IP. Is this possible? I would assume with clever NAT I could do it, but I am not sure (even less sure what VM solutions support it).

Otherwise, I will only be able to have 3 VM, as 1 IP is used by the host, which would require buying more IPs.

Last edited by ThelenShar; 12-27-2010 at 11:14 PM.
 
Old 12-27-2010, 07:59 AM   #2
kirukan
Senior Member
 
Registered: Jun 2008
Location: Eelam
Distribution: Redhat, Solaris, Suse
Posts: 1,278

Rep: Reputation: 148Reputation: 148
If your Server have capacity(memory cpu and disk) you can run 4 VM with private IP's, NAT the local VM IP's with respective public IP on default gateway from where the local traffic route to the internet(may be it could be a router)
 
Old 12-27-2010, 02:13 PM   #3
telecom_is_me
Member
 
Registered: Jun 2008
Location: Upstate NY
Distribution: Fedora on the desk / Gentoo in the Racks
Posts: 36

Rep: Reputation: 15
You can apply multiple public ip's to the same interface on your host system by simply adding virtual interfaces with ifconfig. As in, "ifconfig eth0 192.168.1.2", "ifconfig eth0:1 192.168.1.3", "ifconfig eth0:2 192.168.1.4" and so on. This enables one physical interface to have multiple ip's. Now yes it's true that there are better ways of doing this, the fact is that this works quick and simple. As for binding the interfaces to your virtual machines, that's a much more involved question and depends on what virtualization system your using.
 
Old 12-27-2010, 11:13 PM   #4
ThelenShar
LQ Newbie
 
Registered: Nov 2009
Posts: 14

Original Poster
Rep: Reputation: 0
Neither of you understand what I want to do, sadly.
 
Old 12-28-2010, 12:02 AM   #5
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
or maybe you aren't understanding the answer given?

it would be the HOST operating system that does the NAT translation, not the VM guests

you could do something like this
Code:
#!/bin/bash
WANIF='eth0'
WANMASK='255.255.255.0'
ifconfig $WANIF:1 X.X.X.106 netmask $WANMASK
ifconfig $WANIF:2 X.X.X.107 netmask $WANMASK
ifconfig $WANIF:3 X.X.X.108 netmask $WANMASK

iptables -t nat -p tcp -m tcp --dport 80 -I PREROUTING -d X.X.X.105 -j DNAT --to Y.Y.Y.19:80
iptables -t nat -p tcp -m tcp --dport 80 -I PREROUTING -d X.X.X.106 -j DNAT --to Y.Y.Y.20:80
iptables -t nat -p tcp -m tcp --dport 80 -I PREROUTING -d X.X.X.107 -j DNAT --to Y.Y.Y.21:80
iptables -t nat -p tcp -m tcp --dport 80 -I PREROUTING -d X.X.X.108 -j DNAT --to Y.Y.Y.22:80

iptables -I FORWARD -d X.X.X.105 -p tcp --dport 80 -j ACCEPT
iptables -I FORWARD -d X.X.X.106 -p tcp --dport 80 -j ACCEPT
iptables -I FORWARD -d X.X.X.107 -p tcp --dport 80 -j ACCEPT
iptables -I FORWARD -d X.X.X.108 -p tcp --dport 80 -j ACCEPT

iptables -t nat -I POSTROUTING -s Y.Y.Y.19 -j SNAT --to X.X.X.105
iptables -t nat -I POSTROUTING -s Y.Y.Y.20 -j SNAT --to X.X.X.106
iptables -t nat -I POSTROUTING -s Y.Y.Y.21 -j SNAT --to X.X.X.107
iptables -t nat -I POSTROUTING -s Y.Y.Y.22 -j SNAT --to X.X.X.108
X.X.X.105 is assumed to be the actual eth0 IP address
the scripts shown here are used on a dd-wrt router, so the first lines specifying the interface and defining the virtual IPs would probably be better done in /etc/network/interfaces (or equivilent for fedora), but the rest is generic enough that it should run on almost ANY *NIX setup that uses iptables

replacing the X.X.X addresses with the PUBLIC IP addresses
and the Y.Y.Y addresses with the PRIVATE IP addresses of the virtual machines
and of course you would repeat the lines from the first two sections for each combination of public addr/private addr/port (one port per public IP)

of course the above assumes that the VMs are web servers (port 80), but you could easily change the port numbers to suit whatever services are running on each, of course if one is a web server, one a mail server, and one an ftp server then with the above setup you only would in theory need one public ip

Code:
#!/bin/bash
iptables -t nat -p tcp -m tcp --dport 80 -I PREROUTING -d X.X.X.105 -j DNAT --to Y.Y.Y.19:80
iptables -t nat -p tcp -m tcp --dport 21 -I PREROUTING -d X.X.X.105 -j DNAT --to Y.Y.Y.20:21
iptables -t nat -p tcp -m tcp --dport 25 -I PREROUTING -d X.X.X.105 -j DNAT --to Y.Y.Y.21:25
iptables -t nat -p tcp -m tcp --dport 110 -I PREROUTING -d X.X.X.105 -j DNAT --to Y.Y.Y.22:110

iptables -I FORWARD -d X.X.X.105 -p tcp --dport 80 -j ACCEPT
iptables -I FORWARD -d X.X.X.105 -p tcp --dport 21 -j ACCEPT
iptables -I FORWARD -d X.X.X.105 -p tcp --dport 25 -j ACCEPT
iptables -I FORWARD -d X.X.X.105 -p tcp --dport 110 -j ACCEPT

iptables -t nat -I POSTROUTING -s Y.Y.Y.19 -j SNAT --to X.X.X.105
iptables -t nat -I POSTROUTING -s Y.Y.Y.20 -j SNAT --to X.X.X.105
iptables -t nat -I POSTROUTING -s Y.Y.Y.21 -j SNAT --to X.X.X.105
iptables -t nat -I POSTROUTING -s Y.Y.Y.22 -j SNAT --to X.X.X.105
the above are scripts that would have to be run every time the computer boots


this splits multiple incoming ports from the same IP address to each virtual machine
either way can be done but either way as i mentioned, NAT is the responsibility of the HOST (the os running on the REAL machine) to act as the traffic cop so to speak that directs the traffic to the proper VIRTUAL machines

this is assuming you are using a LINUX based os for your host OS, if you are using windows as your host os, good luck

(yes im sure someone will pick the above scripts apart and find something wrong, but you get the general idea i hope)

Last edited by frieza; 12-28-2010 at 12:40 AM.
 
Old 12-28-2010, 02:23 AM   #6
ThelenShar
LQ Newbie
 
Registered: Nov 2009
Posts: 14

Original Poster
Rep: Reputation: 0
*sigh*

I shouldn't have mentioned NAT, everyone seems to be getting caught up in that >_<

We don't need/want any NAT for 3 of the public IPs, they can just be routed normally to the VM without fiddling.

The problem is, the VM host needs an IP address, meaning that somehow the last VM will need to be NAT'd or something, such that it can 'be' the host IP.

I am assuming I can just change the ports for the host server (ssh, ftp, VM control port etc) to something else (say in 60k range), but outside of that we don't want to have to manually NAT everything from guest 4. ie, 1-59999 will be NAT'd automatically.

I think there isn't a very simple or clean solution, it might just require purchasing more IPs (which sadly costs over $100USD a month >_<)
 
Old 12-28-2010, 11:29 AM   #7
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
if that's the case then you probably just need to create a bridged interface between the real network card and the virtual network card, that way the virtual nics are directly exposed to the lan but what i was describing was more along the lines of port forwarding, which leaves any other port not assigned to the vms open to the host, and nat isn't a manual process per-se other then configuring the script and setting it to run on boot, after that it's automated

Last edited by frieza; 12-28-2010 at 11:32 AM.
 
Old 12-28-2010, 11:31 PM   #8
ThelenShar
LQ Newbie
 
Registered: Nov 2009
Posts: 14

Original Poster
Rep: Reputation: 0
Yea I would want the VM to have all the ports though, bar maybe a couple on the host.

Looks like I just need to buy another IP >_<
 
  


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
VirtualBox: Slackware64 host and guest; NFS mount from host fails catkin Linux - Virtualization and Cloud 0 11-15-2010 06:54 AM
How to assign public IP to vmware guest OS cucolin@ Linux - Software 12 02-24-2009 05:00 PM
VirtualBox Networking (NAT) not working on XP host with Mandriva guest FreeRadical2600 Linux - Newbie 9 10-29-2008 08:12 AM
Public IP behind NAT abdul_zu Linux - Networking 12 07-08-2005 02:42 AM
real routing under nat routing nothingmuch Linux - Networking 4 10-27-2003 03:11 PM

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

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