# How can I set up a static IP? ISP needs DHCP.

## raid517

Hi I am a bit of a networking n00b. Anyhoo, for reasons of convienience I want to change my network configuratiion and give my main PC a fixed IP on my network. Basically I want that IP to be 192.168.1.100 - which is within a range of about 100 static IPs I have defined on my router (with about 250 above this reserved for DHCP).

Well anyway the thing is, I am a little nervous that I could mess up my networking completely if I get it wrong, especially seeing as DHCP is working great. I am also a little confused by some of the questions netsetup asks. I mean, what is the broadcast address? What exactly should I put here?

The problem is that my ISP expects me to connect via DHCP - so so long as I can connect externally to my ISP and still have an internal static ip for my PC - that is exactly what I would like to do.

Basically my router has an address of 192.168.1.1

I have a predefined range of static IPs I can use on my lan which is goes from 192.168.1.2 to 192.168.1.110. I have a number of applications which in order to function correctly must have the appropriate ports open - and so I have to be able to define a static IP for them if I am to get them to work.

Currently they all expect the PC on the lan to have an address of 192.168.1.100.

How can I make sure I can give my Gentoo install the correct static IP on my lan without loosing my internet connection?Last edited by raid517 on Thu Aug 05, 2004 10:50 am; edited 1 time in total

----------

## snuck

I'm not exactly a networking guru, but if I'm wrong I'm sure someone will correct me...

To give a box on your lan a static IP add this to your dhcpd.conf on your router:

host host_name_Here {

        hardware ethernet mac_address_here;

        fixed-address ip_address_you_want_it_to_have_here;

}

To find out the mac address do (as root) 

#ifconfig 

on the box you want to give the static address.

HTH

snuck.

----------

## Nossie

Sorry, but I don't completely understand your question.

The router you are talking about, is it a Gentoo box, or a 'hardware' router / modem ?

Your internal network is 192.168.1.0 i assume with netmask 255.255.255.0 (this can also be written as 192.168.1.0/24) If this is the case your broadcast address will be 192.168.1.255

As long as you stay in the range of 192.168.1.2 to 192.168.1.254 with netmask 255.255.255.0 you will be ok concerning your connectivity to the router (as long as the ip address you set on your computer doesn't conflict with (is the same as) another computer).

As I understand it, your router is a dhcp server, ad it gives ip numbers from .110 to .254 If this is true, you can manually set you IP to anything lower than 192.168.110 (except for .1 of course)

I hope this makes some sense to you...

greetz,

Nossie

----------

## raid517

Yes it is a router. (Well it's a combo router and adsl modem in one external box). And Nossie what you said makes perfect sense to me. And you got my setup exactly right too.

However I did the net-setup thing and I entered the values you suggested, giving myself an IP of 192.168.1.100 and so on. In actual fact, netsetup guessed the rest giving me a broadcast address of 192.168.1.255 a network mask of 255.255.222.0 and I filled in the gateway address for eth0 as 192.168.1.1 - which I assume is the address of my router. But when I did this I lost my internet connection.

Is there something I'm missing here?

GJ

----------

## raid517

Lol, never mind. Maybe I should try rebooting once in a while. It's been a long time - but anyhoo that seemed to resolve it.

Just one thing though, does this mean that I actually need DHCP on my Linux box any more, or can I disable it? I only ask as it really slows down boot quite a lot as DHCP looks for a server and then eventually gives up as it isn't being used.

If so how can I safely do this? I mean how can I do this in a way that makes it easy to renable it if I need to?

GJ

----------

## Nossie

Hi,

Yes you can disable the dhcp client on your linux box. Now you have manually cofigured your ip, the dhcp client doesn't do anything anymore (except lag your boot time).

Nossie

----------

## raid517

Erm.. so how do I do that? And more importantly, how do I test that I have got the static IP address that I wanted (i.e.192.168.1.100)? I ask as I have already configure my system for a static IP, which *appears* to be working. But right now I have no way to confirm this.

Also what other software is there on a fairly raw gentoo install that I might need to consider if I wanted to gurantee that I left ports open for my favorite applications in Linux? (I speak specifically in this instance of Xmule). Because right now I'm suspicious that although I have configured a static IP and have opened the appropriate ports on my router that Xmule is still complaining it can't reach my ports. So it seems that either my static IP isn't running correctly yet, or something else I'm not familiar with is blocking the ports.

Has any one got any possible hints?

GJ

----------

## ronnie

Actually, to switch from dhcp to static, you should edit /etc/conf.d/net and

1. comment out the line iface_eth0="dhcp" so it reads

```
#iface_eth0="dhcp"
```

2. uncomment and change values in the line starting with #iface_eth0=" so it reads something like this:

```
iface_eth0="192.168.1.100 broadcast 192.168.1.255 netmask 255.255.255.0"
```

3. fix default route (the last line in the file) to:

```
gateway="eth0/192.168.1.1"
```

On your next boot dhcp client will not run at all. /etc/init.d/net.eth0 restart makes changes without reboot. To display network info, run (as root):

```
# ifconfig eth0
```

All examples presumes you are using eth0 as your network interface.

----------

## raid517

Thanks, that worked great and into the bargain i learned some very neat stuff about networking too. I now have a super high Xmule id (meaning my ports can be raeched) and can now choose which servers I want to connect to at will.

Thanks again.

GJ

----------

## raid517

There is only one thing though... DHCP came back after I rebooted even though I followed your instructions to the letter. Now I have lost the high ID in Xmule I had before and my ports are unreachable.

How do i prevent DHCP from starting during boot at all?

It is proving to be somewhat troublesome to get rid of it. 

GJ

----------

## Yoda_Oz

im no networking guru or linux guru either, but like what ronnie said, if you disable anything that refers to dhcp in your /etc/conf.d.net file then dhcp shouldnt start at boot. have you noticed that your eth0 card gets initialised first and then dhcp starts? this is because when the interface net.eth0 is initialised it searches through the /etc/conf.d/net file for the properties to give that interface then its loads them. if it finds that it needs to load dhcp then it will load dhcp.

people... please correct me if im wrong as im trying to learn too!

i did learn something today about xmule! thanks raid517 because i didnt know why i was always connected as a lowID, it was because i had dhcp set and not a static ip. now i have a static ip and i have a highID!!! yay!!!

----------

## raid517

Well I am only very pleased that in the process of helping myself I was able to help someone else too.  :Smile: 

However despite double checking my /etc/conf.d/net file I making sure that everything with regard to dhcp is commented out, dhcp is still loading and controlling my eth0 after a reboot.

I can manually follow the instructions here and can obtain a static IP, but this goes away after a reboot and dhcp takes over again.

Here is the layout of my /etc/conf.d/net file:

```
# /etc/conf.d/net:

# $Header: /home/cvsroot/gentoo-src/rc-scripts/etc/conf.d/net,v 1.7 2002/11/18 19:39:22 azarah Exp $

# Global config file for net.* rc-scripts

# This is basically the ifconfig argument without the ifconfig $iface

#

#iface_eth0="192.168.0.2 broadcast 192.168.0.255 netmask 255.255.255.0"

#iface_eth1="207.170.82.202 broadcast 207.0.255.255 netmask 255.255.0.0"

# For DHCP set iface_eth? to "dhcp"

# For passing options to dhcpcd use dhcpcd_eth?

#

iface_eth0="192.168.1.100 broadcast 192.168.1.255 netmask 255.255.255.0"

#dhcpcd_eth0="..."

# For adding aliases to a interface

#

#alias_eth0="192.168.0.3 192.168.0.4"

# NB:  The next is only used for aliases.

#

# To add a custom netmask/broadcast address to created aliases,

# uncomment and change accordingly.  Leave commented to assign

# defaults for that interface.

#

#broadcast_eth0="192.168.0.255 192.168.0.255"

#netmask_eth0="255.255.255.0 255.255.255.0"

# For setting the default gateway

#

gateway="eth0/192.168.1.1"
```

Which is accurate as far as I'm aware.

So the question is, how on earth is this possible?

I ran the netsetup software too, but again dhcp refused to go away.

Has anybody got any suggestions?

----------

## Yoda_Oz

im not sure which config file it would be in (somebody help me) but is the program/script 'dhcpcd' loaded anywhere in the boot process?

for eg. it would be somewhere saying:

```

dhcpcd ethx

```

perhaps you could try:

```

rc-update -s

```

that will show what scripts are loaded...

haha, i dont know the exact code as im very new to linux, but try something similar to that maybe. i dont take responsibility for destroying your computer though...hehe/

----------

## raid517

Well this is what we have:

```
/home/raid516 ;) rc-update -s

           alsasound | boot

                apmd |

               aumix |

          autoconfig |      default

            bootmisc | boot

          bootsplash |      default

             checkfs | boot

           checkroot | boot

               clock | boot

         consolefont | boot

         crypto-loop |

               cupsd |

          domainname |

              esound |

                famd |      default

              freevo |

            gkrellmd |

                 gpm |

              hdparm |

            hostname | boot

             hotplug |

             keymaps | boot

              kismet |

               lircd |

                lisa |

               local |      default nonetwork

          localmount | boot

             metalog | boot default

             modules | boot

               mysql |      default

         mythbackend |

           neostrada |

             nessusd |

            net.eth0 |

              net.lo | boot

            net.ppp0 |

            netmount |      default

                nscd |

             numlock |

             portmap |

             reslisa |

           rmnologin | boot

            rp-pppoe |

              rsyncd |

               samba |

              serial | boot

          speedtouch |

              splash |      default

                sshd |

             urandom | boot

              vmware |      default

             winbind |

                 xdm |      default

                 xfs |
```

Am I missing it? I can't see it there? Maybe I should try to find the dhcp script and just rename it. But that is a bit of a hack really as I would prefer to disable it properly so I can renable it if the occasion ever demands it.

GJ

----------

## Yoda_Oz

well, we've eliminated the dhcpcd thing then...

something is calling that script at boot. i cant tell you what that is though. i suggest you ask around how to disable dhcp at boot because thats what seems to be the prob... sorry i couldnt help... but dont give up!!!

reply post when you work it out so i can learn too mate.

----------

## tapted

Check out http://gentoo-wiki.com/HOWTO_setup_a_home-server. Make sure you skim through the whole thing before doing stuff though. It got me going in no time  :Wink: 

----------

## raid517

Well I'm completely stuck too. Surely we have some networking gurus round here who know what's going on?

I tried as I said just renaming the dhcp binary, but this caused me to loose net connectivity completely on the net boot. I guess this is because whatever script is running is telling the system it should expect dhcp.

Thanks for trying anyway - but I sure hope someone else will pick this up.  :Sad: 

GJ

----------

## raid517

 *tapted wrote:*   

> Check out http://gentoo-wiki.com/HOWTO_setup_a_home-server. Make sure you skim through the whole thing before doing stuff though. It got me going in no time 

 

Thanks for the pointer. Unfortunately the problem is that I'm not trying to start a server, I'm trying to stop one, specifically DHCP.

I read through that tutorial and it touches on much of what has been said here.

Unfortunately the DHCP section only discusses starting DHCP and not how to switch from DHCP to static networking. There is no mention that I can see there how to do this.

Again, thanks for the input. Everyone's opinions are welcome.

GJ

----------

## nobspangle

It doesn't look like your net script is set to run

```
rc-update add net.eth0 default
```

will add it to the default runlevel

----------

## tapted

 *raid517 wrote:*   

> 
> 
> Unfortunately the DHCP section only discusses starting DHCP and not how to switch from DHCP to static networking. There is no mention that I can see there how to do this.

 

The distinction is moot.

If you use dnsmasq, it will first try to assign IP addresses found in your /etc/hosts file (based on the hostname that each computer tells the dhcp server it is -- look at /var/log/messages to find out what this is). This is what I've done myself for my intranet.

Alternatively, you can edit 

/etc/dnsmasq.conf

and assign IP addresses based on MAC addresses -- eg

dhcp-host=11:22:33:44:55:66,192.168.0.60

IMO dhcp is the shiznit -- it tends to "Just Work". dnsmasq is especially good, becuase it lets you effectively inherit DNS names...

on another note, have you tried

emerge unmerge dhcp

? I don't think you need it, despite your problems when you renamed it. I certainly do not have it and my Gentoo box is acting as a gateway fine.

Moo

----------

## raid517

Thanks guys. The truth is it would be impossible for me to run Linux/gentoo without your help, so your input is very much appreciated.

Adding eth0 to the default run level seems to have done  the trick. However DHCP continues to to run at boot time. Only in this instance it is no longer being used. I have done an emerge search for DHCP and have unmerged everything that related to dhcp. According to emerge I no longer have anything to dhcp installed. Yet dhcp continues to run at boot time.

The only drawback is that it slows down my boot times slightly.

Lol, well it might not be a bad thing. I mean if I can have a static IP and still have DHCP running, then at least if there is a scanario where I need to assign dhcp to a device connected directly to my PC, I should still be able to do it.

But I sure wish I understood after all I have done *why* it is still able to run. Not knowing is a bit too much live vodoo for me. I prefer to understand these things.

Anyhoo, at least I have what is a fairly distinct resolution.

As I said, thanks for your input. I have learned a lot and it's pretty much all down to you guys.

Best regards,

GJ

----------

## raid517

PS

 how do I check what my IP is from the CL? I know how to do it in Windows, but I just want to confirm with my own eyes that I am finally up and running.

GJ

----------

## Yoda_Oz

ifconfig ethx - where x is a number. ususally 0 or 1.

----------

## raid517

Yeah that works thanks.

```
eth0      Link encap:Ethernet  HWaddr 00:50:8D:F6:4A:3B

          inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0

          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:126 errors:0 dropped:0 overruns:0 frame:0

          TX packets:166 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:113932 (111.2 Kb)  TX bytes:14089 (13.7 Kb)

          Interrupt:20
```

I am still curious how dhcp could work even though by all the laws of logic it shouldn't even be there any more. But oh well, this is still genuine progress.

GJ

----------

## Yoda_Oz

glad to help...

yeah that dchp thingie is kinda strange... oh well, at least it all works!

----------

## eatjello

Also, make sure you don't have DHCP autoconfiguration compiled into the kernel... if you use menuconfig with 2.6 kernel, it's under Device Drivers -> Networking Support -> Networking Options -> IP: Kernel level autoconfiguration -> IP: DHCP Support.

----------

## raid517

Lol, no it's not there. I mean it's switched off.

BUt regardless it's still working. Despite even changing the kernel completely.

It defies reasoning.

GJ

----------

## Yoda_Oz

funny,

im using genkernel and dhcp doesnt even load at startup even though im using dhcp for my network!!!

----------

