You are not logged in.

#1 2012-04-18 10:07:08

kYd
Member
Registered: 2009-01-20
Posts: 78

[Semi-Solved] Two IPs on one NIC

Semi-solved: See end of this post

I have a dedicated server with OVH, using Arch, which at the moment is more for fun and to learn from than any thing serious; I have managed to set it up to run as both a mail server and a seedbox, but I would like to keep the IPs for each totally independent and so I'm paying for another IP.

I've read this wiki article on IP aliasing using netcfg which seems to cover what I need, but upon executing: netcfg eth0-ip2, with eth0-ip2 being the profile I have created containing the configuration below, the whole internet connectivity goes down server side, I no longer have any access via SSH or otherwise, and so I'm forced to do a hard reboot via OVH's management page.

The configuartion I'm using:

#/etc/network.d/eth0-ip2
#First IP setup in rc.conf, 2nd here.
CONNECTION='ethernet'
DESCRIPTION='Second IP on the NIC.'
INTERFACE='eth0'
IP='static'
ADDR='92.113.1.197'
GATEWAY='92.113.1.254'

The IP schemes as follows:

#IP1 - Setup in rc.conf
IP: 172.29.60.31
Netmask: 255.255.255.0
Broadcast: 172.29.60.255
Gateway: 172.29.60.254

#IP2 - Setup using netcfg
IP: 92.113.1.197
Netmask: 255.255.255.255
Broadcast: 92.113.1.255
Gateway:92.113.1.254

Admittedly, networking isn't forte. Is there something obvious I am missing?

Thanks.

--------------------------

Solution:

Setup the first IP within rc.conf as per usual, then using netcfg (from the repos) create a profile at /etc/network.d/eth0-ip2 similar to the below

CONNECTION='ethernet'
DESCRIPTION='Five different addresses on the same NIC.'
INTERFACE='eth0'
IP='static'
ADDR='1.2.3.4'
#GATEWAY='1.2.3.1'
POST_UP='ip addr add 1.2.3.4/32 brd 1.2.3.255 dev eth0 label eth0:1'
POST_DOWN='ip addr del 1.2.3.4 dev eth0'

and then activate the profile with: netcfg eth0-ip2
Specifying the gateway resulted in netcfg failing, hence why this is only semi-solved.

Last edited by kYd (2012-04-18 19:13:03)

Offline

#2 2012-04-18 10:19:22

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: [Semi-Solved] Two IPs on one NIC

Isn't creating a virtual interface (e.g. eth0.0) the right way to do this?

http://www.cyberciti.biz/tips/howto-con … -vlan.html

Last edited by .:B:. (2012-04-18 10:21:07)


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#3 2012-04-18 10:25:50

kYd
Member
Registered: 2009-01-20
Posts: 78

Re: [Semi-Solved] Two IPs on one NIC

.:B:. wrote:

Isn't creating a virtual interface (e.g. eth0.0) the right way to do this?

http://www.cyberciti.biz/tips/howto-con … -vlan.html

I was under the (wrong?) impression that this is what netcfg would be doing.

Offline

#4 2012-04-18 10:34:49

Gcool
Member
Registered: 2011-08-16
Posts: 1,456

Re: [Semi-Solved] Two IPs on one NIC

It's indeed possible to setup vlans using netcfg. Have a look at this wiki article.


Burninate!

Offline

#5 2012-04-18 11:05:46

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: [Semi-Solved] Two IPs on one NIC

kYd, you haven't read the wiki article thoroughly enough - specifically, this bit:

If you want to use multiple IP addresses on an interface, you will have to use netcfg and its POST_UP and PRE_DOWN commands

(my emphasis)
Read it again, and note in particular the POST_UP and PRE_DOWN elements in the posted profile.

Offline

#6 2012-04-18 11:25:28

Gcool
Member
Registered: 2011-08-16
Posts: 1,456

Re: [Semi-Solved] Two IPs on one NIC

If the only thing you want to do is simply have 2 ip addresses on one interface, then the use of POST_UP and PRE_DOWN will suffice indeed as tomk mentioned (no need to mess around with vlans). It's even literally documented on the netcfg wiki page.


Burninate!

Offline

#7 2012-04-18 15:17:35

kYd
Member
Registered: 2009-01-20
Posts: 78

Re: [Semi-Solved] Two IPs on one NIC

tomk wrote:

If you want to use multiple IP addresses on an interface, you will have to use netcfg and its POST_UP and PRE_DOWN commands

Sorry, I had yesterday played around with the POST_UP and PRE_DOWN commands, but after looking at other tutorials I assumed it wasn't needed.

If I add the following commands:

....
POST_UP='ip addr add 92.113.1.197/32 brd 92.113.1.255 dev eth0 label eth0:1'
POST_DOWN='ip addr del 192.113.1.197 dev eth0'

Upon execution I still get the same behaviour (connectivity is lost until reboot), with the following error:

sudo netcfg eth0-ip2
:: eth0-ip2 up            [BUSY]

RTNETLINK answers: File exists
 > Adding gateway 92.113.1.254 failed 

If I omitt the "gateway=.." directive from the profile, then it works. I can connect over SSH using either IP, but all the traffic is leaving through the initial gateway for IP-1.
I wanted, if possible, and as I say networking isn't my forte, say if I create an SSH tunnel for web browsing connecting to IP2, then my IP to appear as if it is IP2, but it is still using the initial IP-1.

Last edited by kYd (2012-04-18 15:18:59)

Offline

#8 2012-04-18 15:42:55

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: [Semi-Solved] Two IPs on one NIC

I recommend you do all this manually at first - netcfg (and other such tools) are useful, but they can also get in the way, particularly if you're still trying to learn stuff. I think you should only write profiles when you have a clearer understanding of how it actually works.

Unlike the wiki example, your two IP addresses are on different subnets, so you need to look into setting appropriate routes for each one.

Offline

#9 2012-04-18 16:15:49

kYd
Member
Registered: 2009-01-20
Posts: 78

Re: [Semi-Solved] Two IPs on one NIC

tomk wrote:

I recommend you do all this manually at first - netcfg (and other such tools) are useful, but they can also get in the way, particularly if you're still trying to learn stuff. I think you should only write profiles when you have a clearer understanding of how it actually works.

Unlike the wiki example, your two IP addresses are on different subnets, so you need to look into setting appropriate routes for each one.

Ok, thanks. I'll try and have a look around for resources about this topic, albeit I'm not too sure what I should be searching for, so if you have anything specific that you feel would be useful then I'd appreciate that.

Offline

#10 2012-05-08 13:35:15

xintron
Member
From: Sweden
Registered: 2008-09-25
Posts: 32
Website

Re: [Semi-Solved] Two IPs on one NIC

Seems like this might be a good thread to ask about a similar setup. My ISP is giving me 5 external IP-addresses but these are assigned from their DHCP-server so my question is simple: would this setup work just as well with IP='DHCP' instead of assigning it statically (which I can't do)? So that my one NIC fetches all five IP-adresses from my ISP.

Offline

#11 2012-05-08 13:53:48

Gcool
Member
Registered: 2011-08-16
Posts: 1,456

Re: [Semi-Solved] Two IPs on one NIC

It won't be as simple as that I'm afraid. Most likely the dhcp server will only assign 1 ip per mac address. So in order to get 5 ip's on the same box, you'll probably have to create a few virtual interfaces (each with a unique mac address) and have each sent a dhcp request to the dhcp server.


Burninate!

Offline

#12 2012-05-08 14:55:03

xintron
Member
From: Sweden
Registered: 2008-09-25
Posts: 32
Website

Re: [Semi-Solved] Two IPs on one NIC

So it should be solvable with a vlan-setup using netcfg and PRE_UP to change the mac-addresses (or using the netcfg-profile that requests the first IP and then POST_UP creating the other ones manually and spoofing the mac-address)?

Offline

#13 2012-05-08 15:11:21

Gcool
Member
Registered: 2011-08-16
Posts: 1,456

Re: [Semi-Solved] Two IPs on one NIC

That's the idea indeed.


Burninate!

Offline

#14 2012-05-08 15:59:38

xintron
Member
From: Sweden
Registered: 2008-09-25
Posts: 32
Website

Re: [Semi-Solved] Two IPs on one NIC

Did try this on my LAN and saw that the DHCP-server does handle the request correctly answering with an OFFER but the machine sending DISCOVER never sees this OFFER which causes it to fail. At least we're (I'm) getting closer!

Edit:
So, I've managed to request two IP's from my ISP using the following setup:

ip add link eth0 name eth0:0 address <spoofed mac> type vlan id 0
ip add link eth0 name eth0:1 address <another spoofed mac> type vlan id 1
dhcpcd eth0:0
dhcpcd -k eth0:0 && dhcpcd eth0:1 # the release is needed to stop dhcpcd to request the IP bound to eth0:0

My current problem is that the routing doesn't work at all (I've tried telling dhcpcd to not set the gateway but that didn't help). Is this a solution worth working on and setup routes for each new IP (different tables even if the gateway will be the same for all IP's?)?

Last edited by xintron (2012-05-08 16:37:57)

Offline

Board footer

Powered by FluxBB