# Can I lock the ip addresses my router gives to the lan?

## Kasumi_Ninja

I would like to give the computers in my lan a fix ip. Is this possible? If so how do I properly configure Gentoo?  Should I fill in the desired ip address in /etc/conf.d/net?

----------

## magic919

Yes.

----------

## psomas

 *Aniruddha wrote:*   

> I would like to give the computers in my lan a fix ip. Is this possible? If so how do I properly configure Gentoo?  Should I fill in the desired ip address in /etc/conf.d/net?

 

if you have a router, and you use dhcpd you could set a very high value for lease time...

or,don't use dhcpd, and configure your network for static ip...

check this...

----------

## Kasumi_Ninja

If I understand correctly I have two options:

1) Specify the desired ip address in /etc/conf.d/net

```
config_eth0=( "192.168.0.2 netmask 255.255.255.0 brd 192.168.0.255" )

routes_eth0=( "default via 192.168.0.1" )
```

2) Or if your router supports it add a DHCP Reservation to your router.

I wonder:

-Do all routers have an option to add a DHCP Reservation?

-If not, will setting the desired ip address in /etc/conf.d/net have the same effect?

----------

## tarpman

I have yet to see a consumer level router that offers static DHCP leases.  My preferred solution is to flash an alternate firmware such as DD-WRT, which offers that and other advanced features.

----------

## Kasumi_Ninja

 *tarpman wrote:*   

> I have yet to see a consumer level router that offers static DHCP leases.  My preferred solution is to flash an alternate firmware such as DD-WRT, which offers that and other advanced features.

 

If I am not mistaken my router (D-link DGL-4300) supports that:

```
Add DHCP Reservation

Enable :    

Computer Name :    <<

IP Address :    

MAC Address :    
```

```
   HCP Reservations List

Enable    Computer Name    MAC Address    IP Address          

   computer_name mac_address    Edit    Delete
```

Since most consumer level router don't provide this functionality I still wonder if setting the desired ip address in /etc/conf.d/net have the same effect as setting a DHCP reservation in a router.

----------

## think4urs11

 *Aniruddha wrote:*   

> -Do all routers have an option to add a DHCP Reservation?

 

some do, some don't; check it's documentation

 *Aniruddha wrote:*   

> -If not, will setting the desired ip address in /etc/conf.d/net have the same effect?

 

if your router (or your dhcp server in general) isn't aware of a box which has an IP configured which is in it's dhcp scope there is a chance that this ip gets assigned to a dhcp client -> double IP in your network.

Normally the scope can be set (e.g. from .10 to .200), then you can savely configure a machine with a static ip <10 or >200

----------

## timeBandit

 *Think4UrS11 wrote:*   

> Normally the [DHCP] scope can be set (e.g. from .10 to .200), then you can savely configure a machine with a static ip <10 or >200

 This is the method I used. My personal, physical computers and VMs are assigned static IPs (/etc/conf.d/net) outside the DHCP address range set in my router (.200 - .239). My office laptop, on the rare occasions I connect it to my home 'net, uses DHCP.

 *tarpman wrote:*   

> I have yet to see a consumer level router that offers static DHCP leases.

 Really?  :Shocked:  I have two from different manufacturers, both fairly ordinary, both several years old and both offer the feature. I wonder if it was more common a few years ago.

@Aniruddha: Note also that a better router will hash MAC addresses to IP leases and store that map indefinitely. The same IP address, if still available, is issued to a previously-seen MAC address if and when it renews an expired lease. My aforementioned laptop has been issued the same IP address for years, even though the lease time is only one week and it may be off the network for months.

----------

## Kasumi_Ninja

Ok I get it. If a router doesn't support a DHCP reservation I must manually this. To achieve this I:

1) Set the ip address scope of the router to >10 or <200

2) Specify the ip address I want in /etc/conf.d/net

I do have some questions about configuring /etc/conf.d/net . According to net.example I enter the following line for a static configuration:

```
# For a static configuration, use something like this

# (They all do exactly the same thing btw)

#config_eth0=( "192.168.0.2/24" )

#config_eth0=( "192.168.0.2 netmask 255.255.255.0" )
```

My questions are:

1) According to the handbook I also need to set "routes_eth0". Is this true?

```
Code Listing 2.6: Manually setting IP information for eth0

config_eth0=( "192.168.0.2 netmask 255.255.255.0 brd 192.168.0.255" )

routes_eth0=( "default via 192.168.0.1" )
```

http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&chap=8#doc_chap2

2) What does the /24 part of 192.168.0.2/24 mean?

3) Is entering config_eth0=( "192.168.0.201 netmask 255.255.255.0" ) in  /etc/conf.d/net enough for the configuration of an static ip?

----------

## think4urs11

 *Aniruddha wrote:*   

> 3) Is entering config_eth0=( "192.168.0.201 netmask 255.255.255.0" ) in  /etc/conf.d/net enough for the configuration of an static ip?

 

As long as you don't want to access the internet yes, otherwise you need the routes_eth0 additionally

/24 is the same as netmask 255.255.255.0; it tells you how much of the 32 bit an IP address (v4) are the network part (those are set to 1) or the host part (those are set to 0)

The network in this case is 192.168.0 - your host is .2

All hosts within the same network can directly communicate with each other. Machines in different networks need a router for that

You only need to configure a router/default gateway if you want to reach other machines outside of your LAN

----------

## Kasumi_Ninja

 *Think4UrS11 wrote:*   

>  *Aniruddha wrote:*   3) Is entering config_eth0=( "192.168.0.201 netmask 255.255.255.0" ) in  /etc/conf.d/net enough for the configuration of an static ip? 
> 
> As long as you don't want to access the internet yes, otherwise you need the routes_eth0 additionally

 

I think I get it! With the routes option you set the ip address of your router right?

@timeBandit

Thanks.  Didn't know that.

----------

