LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Adding virtual interface for IP based virtual host (http://www.linuxquestions.org/questions/linux-general-1/adding-virtual-interface-for-ip-based-virtual-host-626872/)

pridefc 03-09-2008 07:34 PM

Adding virtual interface for IP based virtual host
 
Hello
I'm planning to setup an IP based virtual host in apache.
current system IP: 192.168.1.5

Add ip of 192.168.1.10 by adding a virtual
ifconfig eth0 add 192.168.1.10

Add a second ip 192.168.1.20
ifconfig eth0:1 add 192.168.1.20

Is this correct? And would the virtual interfaces remain intact
after a reboot? If not, how would I go about making them permanent?

Thanks.

0.o 03-09-2008 07:36 PM

Quote:

Originally Posted by pridefc (Post 3083430)
Hello
I'm planning to setup an IP based virtual host in apache.
current system IP: 192.168.1.5

Add ip of 192.168.1.10 by adding a virtual
ifconfig eth0 add 192.168.1.10

Add a second ip 192.168.1.20
ifconfig eth0:1 add 192.168.1.20

Is this correct? And would the virtual interfaces remain intact
after a reboot? If not, how would I go about making them permanent?

Thanks.

ifconfig ethX:1 <ip> netmask <netmask>

I don't know how to tell you to make them persistent because i don't know which distro you are using.

trickykid 03-09-2008 07:37 PM

Is this on a Red Hat or CentOS type system? To make them permanent, just create the ifcfg-eth0:1 and other ones according to the device you created and put these files in /etc/sysconfig/network-scripts

pridefc 03-09-2008 07:40 PM

Sorry, it's Ubuntu 7.10.

And should I be doing eth0:1 for the first virtual interface and eth0:2 for the second instead of eth0 and eth0:1?

Do I need to add the virtual IPs to /etc/hosts file?

Thanks.

trickykid 03-09-2008 07:45 PM

Quote:

Originally Posted by pridefc (Post 3083436)
Sorry, it's Ubuntu 7.10.

And should I be doing eth0:1 for the first virtual interface and eth0:2 for the second instead of eth0 and eth0:1?

Do I need to add the virtual IPs to /etc/hosts file?

Thanks.

eth0:1, eth0:2, eth0:3... see the pattern. And if you had a connection of eth1, you could do eth1:0, eth1:1, eth1:2...

If this is just a local test and you do want to have some type of name resolution, then yes, add them to /etc/hosts if you have no other DNS setup on your network.

And sorry, not Ubuntu user, not sure what files to stick the configurations in to survive a reboot and I'm too lazy to go searching cause I'm not a personal search engine, I'm sure if you tried searching yourself, you'd find the answer rather quickly.

0.o 03-10-2008 04:22 PM

You will have to put them in /etc/network/interfaces

pridefc 03-16-2008 04:52 PM

Would this work?

iface eth0:1 inet static
address 192.168.1.5
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

iface eth0:2 inet static
address 192.168.1.10
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

iface eth0:3 inet static
address 192.168.1.20
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1


All times are GMT -5. The time now is 11:04 PM.