DHCP with Static Addresses

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

DHCP with Static Addresses

Kenneth Jacker
[ sarge ]

Looking in interfaces(5), it doesn't appear that I can include an
"address" line (where I could specify a desired address) within
/etc/network/interfaces for a 'dhcp'-configured interface.

However, what I'd like to do somehow is make my RFC1819 addresses
remain the same at home, but still use DHCP for DNS, etc.  Depending
on what I boot when, the addresses all change thus messing up firewall
settings and other "stuff".

Maybe I must just go with "iface ... static" instead of "iface ... dhcp"?

What would people suggest for this?

Thanks,
--
Prof Kenneth H Jacker       [hidden email]
Computer Science Dept       www.cs.appstate.edu/~khj
Appalachian State Univ
Boone, NC  28608  USA        


--
To UNSUBSCRIBE, email to [hidden email]
with a subject of "unsubscribe". Trouble? Contact [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: DHCP with Static Addresses

Alex Malinovich-2
On Thu, 2005-11-24 at 13:29 -0500, Kenneth Jacker wrote:

> [ sarge ]
>
> Looking in interfaces(5), it doesn't appear that I can include an
> "address" line (where I could specify a desired address) within
> /etc/network/interfaces for a 'dhcp'-configured interface.
>
> However, what I'd like to do somehow is make my RFC1819 addresses
> remain the same at home, but still use DHCP for DNS, etc.  Depending
> on what I boot when, the addresses all change thus messing up firewall
> settings and other "stuff".
>
> Maybe I must just go with "iface ... static" instead of "iface ... dhcp"?
>
> What would people suggest for this?
If you're using DHCP and you want to have "static" IPs for your devices
what you need to do is assign a static lease on the DHCP server.
Assuming you're using dhcpd you'll want something similar to this in
your dhcpd.conf:

host yourhostname {
  hardware ethernet 00:11:22:AA:BB:CC;
  fixed-address 192.168.0.123;
}

If you're also running your own DNS server you can actually specify the
fixed-address line using a DNS name.

If you're not using dhcpd, then you'll need to look for some reference
to assigning a static lease and go from there. Hope that helps.

--
Alex Malinovich
Support Free Software, delete your Windows partition TODAY!
Encrypted mail preferred. You can get my public key from any of the
pgp.net keyservers. Key ID: A6D24837


signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: DHCP with Static Addresses

Hendrik Sattler-3
In reply to this post by Kenneth Jacker
Kenneth Jacker wrote:

> However, what I'd like to do somehow is make my RFC1819 addresses
> remain the same at home

The big question is: why do you actually care for the address? There are only
rare cases where this is actually needed for a client.

HS

--
Mein GPG-Key ist auf meiner Homepage verfügbar: http://www.hendrik-sattler.de
        oder über pgp.net

PingoS - Linux-User helfen Schulen: http://www.pingos.org

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: DHCP with Static Addresses

Kenneth Jacker
  >> However, what I'd like to do somehow is make my RFC1819 addresses
  >> remain the same at home

  hs> The big question is: why do you actually care for the address?
  hs> There are only rare cases where this is actually needed for a client.

Two needs come to mind:

  o ssh-ing to one of the machines ... how do I know its address?

  o printing to one of the machines running CUPS ... again, I must
    specify the addr of the print server machine

If you can suggest a way to do these things, I'll be glad to use your
approach rather than having "fixed" addresses ...


Thanks for your comments!  

  -Kenneth


--
To UNSUBSCRIBE, email to [hidden email]
with a subject of "unsubscribe". Trouble? Contact [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: DHCP with Static Addresses

Kenneth Jacker
In reply to this post by Alex Malinovich-2
  am> If you're using DHCP and you want to have "static" IPs for your
  am> devices what you need to do is assign a static lease on the DHCP
  am> server.  Assuming you're using dhcpd you'll want something
  am> similar to this in your dhcpd.conf:

  am> host yourhostname {
  am>   hardware ethernet 00:11:22:AA:BB:CC;
  am>   fixed-address 192.168.0.123;
  am> }

Good idea!

However, 'dhcpd' is running within my LinkSys router, not on one of my
Debian boxen ...

I spent quite a few minutes going through the router's option pages,
but couldn't see a way to specify this.

Anyone know how to configure a LinkSys router to use the above approach?


Thanks for everyone's comments/suggestions,

  -Kenneth


--
To UNSUBSCRIBE, email to [hidden email]
with a subject of "unsubscribe". Trouble? Contact [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: DHCP with Static Addresses

Maxim Veksler
On 11/25/05, Kenneth Jacker <[hidden email]> wrote:

>   am> If you're using DHCP and you want to have "static" IPs for your
>   am> devices what you need to do is assign a static lease on the DHCP
>   am> server.  Assuming you're using dhcpd you'll want something
>   am> similar to this in your dhcpd.conf:
>
>   am> host yourhostname {
>   am>   hardware ethernet 00:11:22:AA:BB:CC;
>   am>   fixed-address 192.168.0.123;
>   am> }
>
> Good idea!
>
> However, 'dhcpd' is running within my LinkSys router, not on one of my
> Debian boxen ...
>
> I spent quite a few minutes going through the router's option pages,
> but couldn't see a way to specify this.
>
> Anyone know how to configure a LinkSys router to use the above approach?
>
>
> Thanks for everyone's comments/suggestions,
>
>   -Kenneth
>
>
> --
> To UNSUBSCRIBE, email to [hidden email]
> with a subject of "unsubscribe". Trouble? Contact [hidden email]
>
>

I believe you would find man page of interface(5) useful for your needs.
Especially concentrate on the mapping script

Quoting the man page:
<<<
       Stanzas defining logical interfaces start with a line consisting of the
       word  "iface" followed by the name of the logical interface.  In simple
       configurations without mapping stanzas this name should simply  be  the
       name  of  the  physical  interface  to which it is to be applied.  (The
       default mapping script is, in effect, the echo command.)  The interface
       name  is  followed by the name of the address family that the interface
       uses.  This will be "inet" for TCP/IP networking,  but  there  is  also
       some support for IPX networking ("ipx"), and IPv6 networking ("inet6").
       Following that is the name of the method used to configure  the  inter-
       face.
>>>

You could set inside the mapping script a "static" IP but let dhcp
configure the rest.
See also /usr/share/doc/ifupdown/examples/network-interfaces.gz for
"confirmed" mapping examples.

HTH

--
Cheers,
Maxim Vexler (hq4ever).

Do u GNU ?
Reply | Threaded
Open this post in threaded view
|

Re: DHCP with Static Addresses

Alex Malinovich-2
In reply to this post by Kenneth Jacker
On Fri, 2005-11-25 at 11:58 -0500, Kenneth Jacker wrote:

>   >> However, what I'd like to do somehow is make my RFC1819 addresses
>   >> remain the same at home
>
>   hs> The big question is: why do you actually care for the address?
>   hs> There are only rare cases where this is actually needed for a client.
>
> Two needs come to mind:
>
>   o ssh-ing to one of the machines ... how do I know its address?
>
>   o printing to one of the machines running CUPS ... again, I must
>     specify the addr of the print server machine
>
> If you can suggest a way to do these things, I'll be glad to use your
> approach rather than having "fixed" addresses ...
>
>
> Thanks for your comments!  
Actually, in both of these cases I would suggest just running a local
DNS server and enabling dynamic DNS updates.

I actually use a combination of dynamic DNS and static DHCP leases at
home. I have static DHCP pointing to DNS entries. So I can change my
DHCP lease address by changing just the DNS entry.

The only thing that DNS names don't work for sometimes is iptables, so
if you're doing a lot of machine specific filtering and forwarding in
iptables, it's still useful to have static leases defined.

--
Alex Malinovich
Support Free Software, delete your Windows partition TODAY!
Encrypted mail preferred. You can get my public key from any of the
pgp.net keyservers. Key ID: A6D24837


signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: DHCP with Static Addresses

Alex Malinovich-2
In reply to this post by Maxim Veksler
On Fri, 2005-11-25 at 20:14 +0200, Maxim Vexler wrote:

> On 11/25/05, Kenneth Jacker <[hidden email]> wrote:
> >   am> If you're using DHCP and you want to have "static" IPs for your
> >   am> devices what you need to do is assign a static lease on the DHCP
> >   am> server.  Assuming you're using dhcpd you'll want something
> >   am> similar to this in your dhcpd.conf:
> >
> >   am> host yourhostname {
> >   am>   hardware ethernet 00:11:22:AA:BB:CC;
> >   am>   fixed-address 192.168.0.123;
> >   am> }
> >
> > Good idea!
> >
> > However, 'dhcpd' is running within my LinkSys router, not on one of my
> > Debian boxen ...
> >
> > I spent quite a few minutes going through the router's option pages,
> > but couldn't see a way to specify this.
> >
> > Anyone know how to configure a LinkSys router to use the above approach?
--snip--

> I believe you would find man page of interface(5) useful for your needs.
> Especially concentrate on the mapping script
>
> Quoting the man page:
> <<<
>        Stanzas defining logical interfaces start with a line consisting of the
>        word  "iface" followed by the name of the logical interface.  In simple
>        configurations without mapping stanzas this name should simply  be  the
>        name  of  the  physical  interface  to which it is to be applied.  (The
>        default mapping script is, in effect, the echo command.)  The interface
>        name  is  followed by the name of the address family that the interface
>        uses.  This will be "inet" for TCP/IP networking,  but  there  is  also
>        some support for IPX networking ("ipx"), and IPv6 networking ("inet6").
>        Following that is the name of the method used to configure  the  inter-
>        face.
> >>>
>
> You could set inside the mapping script a "static" IP but let dhcp
> configure the rest.
> See also /usr/share/doc/ifupdown/examples/network-interfaces.gz for
> "confirmed" mapping examples.
While it would be possible to write a custom ifupdown script to run
after DHCP supplies you with any necessary info, it would be far from
the ideal solution.

Specifying a static IP in /etc/network/interfaces with the dhcp option
set would also not work as the dhcp option would cause any static IP's
listed to just be ignored.

The "correct" way to do this is to use a static lease. That's the reason
that static leases exist in the DHCP spec in the first place.

--
Alex Malinovich
Support Free Software, delete your Windows partition TODAY!
Encrypted mail preferred. You can get my public key from any of the
pgp.net keyservers. Key ID: A6D24837


signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: DHCP with Static Addresses

Winston Smith-3
In reply to this post by Kenneth Jacker
On Fri, Nov 25, 2005 at 12:02:47PM -0500, Kenneth Jacker wrote:

>   am> server.  Assuming you're using dhcpd you'll want something
>   am> similar to this in your dhcpd.conf:
>
>   am> host yourhostname {
>   am>   hardware ethernet 00:11:22:AA:BB:CC;
>   am>   fixed-address 192.168.0.123;
>   am> }
>
> Good idea!
>
> However, 'dhcpd' is running within my LinkSys router, not on one of my
> Debian boxen ...
>
> I spent quite a few minutes going through the router's option pages,
> but couldn't see a way to specify this.

I have a Linksys wireless router that, as far as I can tell, can't
be configured as suggested above (without changing the firmware).
Fortunately, you can use /etc/dhclient.conf on the client instead of
dhcpd.conf on the router to accomplish something similar.

I have this in /etc/dhclient.conf:
alias {
  interface "eth0";
  fixed-address 192.168.1.101;
  option subnet-mask 255.255.255.0;
}
--------------------------------

And this in /etc/network/interfaces:
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp
----------------------------

This setup works with port forwarding for ssh and, as far as I know,
everything else but openvpn. To make it work for openvpn I also changed
/etc/dhclient-script to promote the fixed-address, which manifests
only as an alias, to the primary address.

$diff -u /etc/dhclient-script.dist /etc/dhclient-script
--- /etc/dhclient-script.dist 2005-11-26 09:01:15.000000000 -0500
+++ /etc/dhclient-script 2005-11-26 09:00:43.000000000 -0500
@@ -123,6 +123,12 @@
   exit_with_hooks 0
 fi
 
+if [ x$alias_ip_address != x ] ; then
+  given_ip_address=$new_ip_address;
+  new_ip_address=$alias_ip_address;
+  alias_ip_address=$given_ip_address;
+fi
+
 if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
    [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
   if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \

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

If you're not familiar with context diffs, the lines beginning with a
single '+' are what was added by me.  Hope that helps.

Win


--
To UNSUBSCRIBE, email to [hidden email]
with a subject of "unsubscribe". Trouble? Contact [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: DHCP with Static Addresses

Jim McCloskey
In reply to this post by Kenneth Jacker
|>   o printing to one of the machines running CUPS ... again, I must
|>     specify the addr of the print server machine

This was why I wanted to assign a fixed address to my desktop machine at home---
it has a printer on the parallel port and it serves as  printserver for all of
the other machines that use the home network (laptops mostly).

But this very simple solution works here. I just have in /etc/network/interfaces:

iface eth0 inet static
address 192.168.1.100
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.1

and the DHCP server in the Linksys router (a Wireless-B) is happy to always assign
the 192.168.1.100 address to the machine in question.

Very unsophisticated, but it does the needful (lets me ssh in and so on),

Jim




--
To UNSUBSCRIBE, email to [hidden email]
with a subject of "unsubscribe". Trouble? Contact [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: DHCP with Static Addresses

H.S.
Jim McCloskey wrote:

> |>   o printing to one of the machines running CUPS ... again, I must
> |>     specify the addr of the print server machine
>
> This was why I wanted to assign a fixed address to my desktop machine at home---
> it has a printer on the parallel port and it serves as  printserver for all of
> the other machines that use the home network (laptops mostly).
>
> But this very simple solution works here. I just have in /etc/network/interfaces:
>
> iface eth0 inet static
> address 192.168.1.100
> network 192.168.1.0
> netmask 255.255.255.0
> broadcast 192.168.1.255
> gateway 192.168.1.1
>
> and the DHCP server in the Linksys router (a Wireless-B) is happy to always assign
> the 192.168.1.100 address to the machine in question.

No, DHCP is doing nothing in this. You have given your machine a fixed
IP address in your LAN and it works perfectly.

Here is what I did to give a machine (laptop) a fixed DHCP address:

In the machine which acts as a router and DHCP server, I have this para
in /etc/dhcpd.conf for my laptop:
#added by HS,08May2005, to assign fixed address to the Dell laptop.
#info from http://www.siliconvalleyccie.com/linux-hn/dchp.htm
host red {
hardware ethernet XY:AB:CD:EF:GH:IJ;
fixed-address 192.168.0.120;
}

Where XY:AB:CD:EF:GH:IJ is the mac address of the interface card of the
laptop and 192.168.0.120 is the IP address I want DHCP server to assign
to the laptop and "red" is the hostname given to the laptop. The
hostname is in combination with this line in the dhcpd.conf file:
option domain-name "myhome.domain";

which makes red.myhome.domain the complete domain name of the laptop.

IIRC, I used this method so that the laptop may be configured to always
look for an address from a DHCP server whether it was at my school or at
home or anywhere else where a DHCP server was running. Having a fixed IP
address was not working in that scenario then. Now, I guess, there are
other more modern methods to make a laptop perfectly mobile in Linux.

Let me know if you have any more questions.
->HS




--
To UNSUBSCRIBE, email to [hidden email]
with a subject of "unsubscribe". Trouble? Contact [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Re: DHCP with Static Addresses

Jim McCloskey
"H.S." <[hidden email]> wrote:

|> > and the DHCP server in the Linksys router (a Wireless-B) is happy
|> > to always assign the 192.168.1.100 address to the machine in  
|> > question.
|>
|> No, DHCP is doing nothing in this. You have given your machine a fixed
|> IP address in your LAN and it works perfectly.

Yes, you're right of course. I had forgotten (it's been a long time
since I set this up) that I had configured the Linksys *not* to assign
the address 192.168.1.100 (the starting point for the range of addresses
it can assign is 192.168.1.101). That way, there are no conflicts.

But yes, it all does work for these very simple purposes.

Jim


--
To UNSUBSCRIBE, email to [hidden email]
with a subject of "unsubscribe". Trouble? Contact [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: DHCP with Static Addresses

Joseph H. Fry
In reply to this post by Kenneth Jacker
On Thursday 24 November 2005 1:29 pm, Kenneth Jacker wrote:

> [ sarge ]
>
> Looking in interfaces(5), it doesn't appear that I can include an
> "address" line (where I could specify a desired address) within
> /etc/network/interfaces for a 'dhcp'-configured interface.
>
> However, what I'd like to do somehow is make my RFC1819 addresses
> remain the same at home, but still use DHCP for DNS, etc.  Depending
> on what I boot when, the addresses all change thus messing up firewall
> settings and other "stuff".
>
> Maybe I must just go with "iface ... static" instead of "iface ... dhcp"?
>
> What would people suggest for this?
>
> Thanks,
> --
> Prof Kenneth H Jacker       [hidden email]
> Computer Science Dept       www.cs.appstate.edu/~khj
> Appalachian State Univ
> Boone, NC  28608  USA


I solved the problem by configuring a second IP to the interface statically
in /etc/network/interfaces:

# The primary network interface
auto eth0
iface eth0 inet dhcp

# Server IP
auto eth0:1
iface eth0:1 inet static
address 192.168.11.10
netmask 255.255.255.0

There are a couple advantages to this.... my favorite is that I can portmap to
the static address in my router and only bind those services to the static IP
while services I use internally (such as samba) are hosted on the dynamic IP.

I hope this helped!

Joe


--
To UNSUBSCRIBE, email to [hidden email]
with a subject of "unsubscribe". Trouble? Contact [hidden email]