Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Adding aliases for static ip's alongside dynamic ip.*update*
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
ZiffyWombat
n00b
n00b


Joined: 06 Sep 2004
Posts: 64
Location: Earth, Europe, Scandinavia, Finland, Nokia

PostPosted: Wed Dec 22, 2004 7:45 pm    Post subject: Adding aliases for static ip's alongside dynamic ip.*update* Reply with quote

Now, this is a good idea (or not, i don't know about it's security problems) if you only have one physical NIC on you're computer but if you have a second NIC then use it for your static ip,

So, if you seriously want to setup your NIC to handle both dynamic and static ip's insert these lines to your /etc/conf.d/net:
Example lines from my config.
Code:
ifconfig_eth0=( "dhcp" )

Code:
alias_eth0=( "192.168.1.2 netmask 255.255.255.0" )


And finally activate configuration with:
Code:
/etc/init.d/net.eth0 restart


and after that you will get this from ifconfig:
Code:

#DYNAMIC#
          eth0      Link encap:Ethernet  HWaddr 00:E0:4C:A9:99:4A 
          inet addr:62.142.253.239  Bcast:62.142.255.255  Mask:255.255.252.0
          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1674374 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1397069 errors:0 dropped:0 overruns:0 carrier:0
          collisions:20258 txqueuelen:1000
          RX bytes:1127061269 (1074.8 Mb)  TX bytes:595917162 (568.3 Mb)
          Interrupt:11 Base address:0xa000
#STATIC#
eth0:1    Link encap:Ethernet  HWaddr 00:E0:4C:A9:99:4A 
          inet addr:192.168.0.2  Bcast:192.168.0.254  Mask:255.255.255.0
          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:110 errors:0 dropped:0 overruns:0 frame:0
          TX packets:110 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:6104 (5.9 Kb)  TX bytes:6104 (5.9 Kb)
          Interrupt:11 Base address:0xa000


have fun. :)
_________________
Nick on freenode #gentoo
NeeXt

---
http://www.gutenberg.org/dirs/1/3/132/132a-h/132a-h.htm


Last edited by ZiffyWombat on Wed Jul 20, 2005 12:25 pm; edited 1 time in total
Back to top
View user's profile Send private message
planet-admin
Apprentice
Apprentice


Joined: 27 Mar 2004
Posts: 213
Location: Boise, ID

PostPosted: Wed Dec 22, 2004 8:15 pm    Post subject: Re: Static ip and dhcp ip on one interface Reply with quote

ZiffyWombat wrote:
Now, this is a good idea (or not, i don't know about it's security problems) if you only have one physical NIC on you're computer but if you have a second NIC then use it for your static ip, this could also cause a few network collisions or it might be my crappy 10mb/s hub, i don't know.


So, if you seriously want to setup your NIC to handle both dhcp and static insert this to your /etc/conf.d/net:

Code:
ifconfig_eth0=( "dhcp" "192.168.0.2 broadcast 192.168.0.255 netmask 255.255.255.0" )


And finally activate configuration with:
Code:
/etc/init.d/net.eth0 restart


and after that you will get this from ifconfig:

Code:
 
#DHCP#
          eth0      Link encap:Ethernet  HWaddr 00:E0:4C:A9:99:4A 
          inet addr:62.142.253.***  Bcast:62.142.255.255  Mask:255.255.252.0
          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1674374 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1397069 errors:0 dropped:0 overruns:0 carrier:0
          collisions:20258 txqueuelen:1000
          RX bytes:1127061269 (1074.8 Mb)  TX bytes:595917162 (568.3 Mb)
          Interrupt:11 Base address:0xa000
#STATIC#
eth0:1    Link encap:Ethernet  HWaddr 00:E0:4C:A9:99:4A 
          inet addr:192.168.0.2  Bcast:192.168.0.254  Mask:255.255.255.0
          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:110 errors:0 dropped:0 overruns:0 frame:0
          TX packets:110 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:6104 (5.9 Kb)  TX bytes:6104 (5.9 Kb)
          Interrupt:11 Base address:0xa000


have fun. :)


This is intriguing.....how can a NIC have two simulatenous addresses? Esp dynamic and static....
_________________
Michael S. Moody
Sr. Systems Engineer
Global Systems Consulting
Web: http://www.GlobalSystemsConsulting.com
Back to top
View user's profile Send private message
ZiffyWombat
n00b
n00b


Joined: 06 Sep 2004
Posts: 64
Location: Earth, Europe, Scandinavia, Finland, Nokia

PostPosted: Wed Dec 22, 2004 8:37 pm    Post subject: Reply with quote

Quote:
This is intriguing.....how can a NIC have two simulatenous addresses? Esp dynamic and static....


I don't know, but it sure does work:)
I stumbled upon it by accident, guess it assings aliases for the NIC or something.
_________________
Nick on freenode #gentoo
NeeXt

---
http://www.gutenberg.org/dirs/1/3/132/132a-h/132a-h.htm
Back to top
View user's profile Send private message
planet-admin
Apprentice
Apprentice


Joined: 27 Mar 2004
Posts: 213
Location: Boise, ID

PostPosted: Wed Dec 22, 2004 8:38 pm    Post subject: Reply with quote

ZiffyWombat wrote:
Quote:
This is intriguing.....how can a NIC have two simulatenous addresses? Esp dynamic and static....


I don't know, but it sure does work:)
I stumbled upon it by accident, guess it assings aliases for the NIC or something.


From all I know about networking, this should be impossible, for all I know about linux, they make the impossible possible.

Michael
_________________
Michael S. Moody
Sr. Systems Engineer
Global Systems Consulting
Web: http://www.GlobalSystemsConsulting.com
Back to top
View user's profile Send private message
wharding
n00b
n00b


Joined: 02 Nov 2004
Posts: 7

PostPosted: Wed Dec 22, 2004 8:50 pm    Post subject: Reply with quote

Is this a by product of multi-homing?

I thought you could multi-home a single nic card by setting multiple static IP addresses. Was never sure you could do it by using DHCP.

And in actuality I have never setup a multi-homed nic card, so I may be WAY off base here in the first place.

I should give this a try.
Back to top
View user's profile Send private message
kimchi_sg
Advocate
Advocate


Joined: 26 Nov 2004
Posts: 2915
Location: Singapore

PostPosted: Thu Dec 23, 2004 3:13 am    Post subject: Reply with quote

I wonder what this would be useful for.

If only i had a NIC with 2 ethernet ports to test this. :D
_________________
Murphy's Law of Gentoo installation: If a compile can fail, it will.

MacGillicuddy's Corollary: At the most inopportune time.

Please search and read the FAQs before posting.
Back to top
View user's profile Send private message
wharding
n00b
n00b


Joined: 02 Nov 2004
Posts: 7

PostPosted: Thu Dec 23, 2004 4:48 am    Post subject: Reply with quote

I don't think you need multiple ethernet ports. What it is useful for is pointing multiple IP addresses to a single NIC card. This way you could load balance the connection plus other fun and useful tricks.

Although, I think I might have had a bit more holiday cheer than I had intended so again I might bit a bit off base ;)
Back to top
View user's profile Send private message
mudrii
l33t
l33t


Joined: 26 Jun 2003
Posts: 789
Location: Singapore

PostPosted: Thu Dec 23, 2004 5:28 am    Post subject: Reply with quote

wow
nice howto
THX
_________________
www.gentoo.ro
Back to top
View user's profile Send private message
Ox-
Guru
Guru


Joined: 19 Jun 2003
Posts: 305

PostPosted: Thu Dec 23, 2004 5:47 am    Post subject: Reply with quote

All I added to /etc/conf.d/net was:
Code:
alias_eth0="192.168.0.2"
This is in addition to the normal dhcp stuff in there:
Code:
iface_eth0="dhcp"
dhcpcd_eth0="-R -N"

This makes eth0 the dhcp assigned address, and eth0:1 is 192.168.0.2.
Back to top
View user's profile Send private message
lothar
Tux's lil' helper
Tux's lil' helper


Joined: 10 Mar 2004
Posts: 87
Location: Norway

PostPosted: Thu Dec 23, 2004 10:24 am    Post subject: Reply with quote

I've used this for some time now. The DHCP recieves IP from my ISP, and I've got a local ip 192.168.0. to get in contact with the other computers in the house + my neighbour :)
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 44178
Location: 56N 3W

PostPosted: Thu Dec 23, 2004 10:49 am    Post subject: Reply with quote

This sets up multiple logical networks over the same physical network
and is called aliasing.

Its not a good idea unless you have a switch to stop the 192.168.x,x packets getting into the internet. They are not publicly routable, so you may get a nastygram from your ISP.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
srlinuxx
l33t
l33t


Joined: 22 Nov 2003
Posts: 627

PostPosted: Thu Dec 23, 2004 5:18 pm    Post subject: Reply with quote

lothar wrote:
I've used this for some time now. The DHCP recieves IP from my ISP, and I've got a local ip 192.168.0. to get in contact with the other computers in the house + my neighbour :)


yeah, my isp assigns a dynamic ip to my adsl modem and yet I have 7 static ips. I use one (well and another for my slave), and it's set up in dns server. ifconfig shows both and both will reach my server.

I handle dhcp and static ip for internal machines by setting them in my servers dhcpd config file - give that mac addys this ip kinda thing.
_________________
--You talk the talk, but do you waddle the waddle?
-Gentoo Monthly Screenshots
Back to top
View user's profile Send private message
RinkyDinks_RJ
n00b
n00b


Joined: 12 Aug 2003
Posts: 42

PostPosted: Sat Dec 25, 2004 4:56 am    Post subject: Reply with quote

Aliases, Subinterfaces, logical interfaces. They all mean the same thing. They are most commonly used for routing and switching purposes, but can be adapted to other uses.
Back to top
View user's profile Send private message
Ateo
Advocate
Advocate


Joined: 02 Jun 2003
Posts: 2021
Location: Republic of California

PostPosted: Fri Feb 11, 2005 10:05 am    Post subject: Reply with quote

planet-admin wrote:
ZiffyWombat wrote:
Quote:
This is intriguing.....how can a NIC have two simulatenous addresses? Esp dynamic and static....


I don't know, but it sure does work:)
I stumbled upon it by accident, guess it assings aliases for the NIC or something.


From all I know about networking, this should be impossible, for all I know about linux, they make the impossible possible.

Michael


Not impossible for networking. In fact, quite common. The pix 520 (cisco firewall) I run, for example... one of the external interfaces has several IPs assigned to it, mainly for one-to-one NAT.. While setup is different between the 2, the concept is the same.
Back to top
View user's profile Send private message
j-m
Retired Dev
Retired Dev


Joined: 31 Oct 2004
Posts: 975

PostPosted: Fri Feb 11, 2005 10:45 am    Post subject: Reply with quote

It is perfectly normal and very useful to have many IP addresses on one NIC. Absolute must, if you need many web sites with their own certificate on one machine. This is what I have on a webhosting server:

Code:

 # ip addr show
1: lo: <LOOPBACK,UP> mtu 16436 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 brd 127.255.255.255 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff
    inet xxx.yyy.254.91/27 brd xxx.yyy.254.95 scope global eth0
    inet xxx.yyy.231.113/28 brd xxx.yyy.231.127 scope global eth0:1
    inet xxx.yyy.231.217/29 brd xxx.yyy.231.223 scope global eth0:14
    inet xxx.yyy.231.114/28 brd xxx.yyy.231.127 scope global secondary eth0:2
    inet xxx.yyy.231.115/28 brd xxx.yyy.231.127 scope global secondary eth0:3
    inet xxx.yyy.231.116/28 brd xxx.yyy.231.127 scope global secondary eth0:4
    inet xxx.yyy.231.117/28 brd xxx.yyy.231.127 scope global secondary eth0:5
    inet xxx.yyy.231.118/28 brd xxx.yyy.231.127 scope global secondary eth0:6
    inet xxx.yyy.231.119/28 brd xxx.yyy.231.127 scope global secondary eth0:7
    inet xxx.yyy.231.120/28 brd xxx.yyy.231.127 scope global secondary eth0:8
    inet xxx.yyy.231.121/28 brd xxx.yyy.231.127 scope global secondary eth0:9
    inet xxx.yyy.231.122/28 brd xxx.yyy.231.127 scope global secondary eth0:10
    inet xxx.yyy.231.123/28 brd xxx.yyy.231.127 scope global secondary eth0:11
    inet xxx.yyy.231.124/28 brd xxx.yyy.231.127 scope global secondary eth0:12
    inet xxx.yyy.231.125/28 brd xxx.yyy.231.127 scope global secondary eth0:13
    inet xxx.yyy.231.218/29 brd xxx.yyy.231.223 scope global secondary eth0:15
    inet xxx.yyy.231.219/29 brd xxx.yyy.231.223 scope global secondary eth0:16
    inet xxx.yyy.231.220/29 brd xxx.yyy.231.223 scope global secondary eth0:17
    inet xxx.yyy.231.221/29 brd xxx.yyy.231.223 scope global secondary eth0:18


Code:

 # ip route show
xxx.yyy.231.216/29 dev eth0  proto kernel  scope link  src xxx.yyy.231.217
xxx.yyy.231.112/28 dev eth0  proto kernel  scope link  src xxx.yyy.231.113
xxx.yyy.254.64/27 dev eth0  proto kernel  scope link  src xxx.yyy.254.91
127.0.0.0/8 dev lo  scope link
default via xxx.yyy.254.94 dev eth0
Back to top
View user's profile Send private message
DeathAndTaxes
Tux's lil' helper
Tux's lil' helper


Joined: 27 Mar 2003
Posts: 124

PostPosted: Sun Feb 13, 2005 6:00 am    Post subject: Reply with quote

Ok, it's nice to see that the gentoo init scripts now allow you to assign one via dhcp and one static, but there's some confusion in this thread about when/where this would be handy and such.

Firstly, you generally do *not* want to assign two IPs on the same subnet to one box...Whether they are aliases on one NIC or are two different NICs. You might not notice a problem, but I'd bet other boxes on the LAN would go crazy with their ARP caches. I did this a couple of times and had some weird problems...I think it's common for people to do this, but I've seen some strangeness in doing this.

***EDIT***Erm, I'm rethinking this. I know someone will point out my flaw, but I'm going to wait until they clarify my error before I respond.***END EDIT***

Second, you *can* add as many aliases (read: different IPs) to a nic as you like (well, almost...There are a few limitations, but the numbers are really large), but again, you do not want to have multiple IPs on the same subnet on one box.

***EDIT***Disregard the not having multiple IPs on the same subnet. My bad...I was thinking of something else. DOH!***END EDIT***

Third, the settings listed in the top post do not specify what the default route is if the DHCP fails. If the DHCP server hands out the default gateway (most do), then you're ok, but if the dhcp process fails, you don't have a default route defined.

Fourth, it's generally a good idea to set a timeout for dhcpclient...This can be set in /etc/conf.d/net on the dhcpcd_ethx lines. An example would be:

Code:

dhcpcd_eth0="-t 5"


This sets the timeout to 5 seconds...You want to set this, believe me...There's nothing worse than having to wait 60 seconds for your dhcp request to time out during boot up.

Fifth, you *could* load-balance if you know what you are doing, but again, the ARP issues can be a nightmare. If you want more bandwidth on a LAN, then you'll either need to get a gigabit card, or you'll need to run multiple NICs on seperate subnets. Just adding more IPs to a NIC will not result in more bandwidth.

Sixth, you can *not* statically assign an IP *and* manually assign another IP on a single interface in windows...Even in winxp. It's silly and it causes many people to think that it "just can't be done". We all know winxp sucks, but this is going too far. ;-)

Ok, so those are my issues in the thread so far. Someone asked what this would be good for. I have a good use for it, and ended up just building another init script to get my solution the way I wanted:

At home, I have a LAN with a DHCP server. The DHCP is NAT'ing my LAN as well. I have a static-assigned IP on each box on my LAN to a 192.168.0.x address with the usual 255.255.255.0 subnet mask. I set up entries in my /etc/hosts file for each box based on this 192.168.0.x address. There is no default gateway specified in my scripts. My DHCP server hands out IPs in the 192.168.1.x range. It also provides a default gateway for this subnet via DHCP. This is how my boxes get their default route.

I often take my boxes to LANparties or to friends' houses. They may have a different network configuration for their LAN, so I get my IPs from them via DHCP, and that provides me with routing information, but I can still hit any other boxes I dragged with me based on the 192.168.0.x addresses...Remember that I set those in my /etc/hosts file.

This allows me to basically take my boxes anywhere and still be able to get into them via the statically-assigned 192.168.0.x addresses, but still have my box automatically integrate with other peoples' LANs.

My ultimate solution for this was to build another init script for the ethernet interface. It basically just runs dhcpcd on the interface (with the -t 5 switch of course). If it fails, I only lose 5 seconds, and can manually assign a default gateway or whatever. Here's a copy of the init script in case anyone is interested:

Code:

#!/sbin/runscript

depend () {
        need net
        after net
        before mysqld
        use logger
}

start() {
        ebegin "Trying dhcpcd for eth0:1"
        /sbin/dhcpcd -t 5 eth0:1
        eend $? "Failed to get IP for eth0:1"
}

stop() {
        ebegin "Shutting down dhcpcd for eth0:1"
        start-stop-daemon --stop --quiet --pidfile /var/run/dhcpcd-eth0\:1.pid
        eend $?
}


This might not be handy anymore since the init scripts supposedly support this, but there it is anyway.
Back to top
View user's profile Send private message
golding
Apprentice
Apprentice


Joined: 07 Jun 2005
Posts: 230
Location: Adelaide / South Australia

PostPosted: Tue Jul 19, 2005 10:18 pm    Post subject: Reply with quote

Would this be any good for getting a print server to be recognised?

I have an adsl router/dhcp server and an HP lan print server. Unfortunately the print server is static at 192.0.0.192 0n 255.255.0.0 while my lan is served from the dhcp on 10.0.0 and 255.255.255.0. I have not been able to browse to the print server, but, I don't want to try this if it is going to bork my connection to the net.
_________________
Regards, Robert

..... Some people can tell what time it is by looking at the sun, but I have never been able to make out the numbers.
Back to top
View user's profile Send private message
ZiffyWombat
n00b
n00b


Joined: 06 Sep 2004
Posts: 64
Location: Earth, Europe, Scandinavia, Finland, Nokia

PostPosted: Tue Jul 19, 2005 11:11 pm    Post subject: Reply with quote

A little update on this.. These days you can just use
for example.
Code:
alias_eth0=( "192.168.1.2 netmask 255.255.255.0" )

It shouldnt break your connection or anything.
I dont see any reason why it wouldnt work on a print server.
_________________
Nick on freenode #gentoo
NeeXt

---
http://www.gutenberg.org/dirs/1/3/132/132a-h/132a-h.htm
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum