LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-09-2008, 02:11 PM   #1
Supporter1984
LQ Newbie
 
Registered: Jan 2008
Distribution: Slackware, Slax
Posts: 16

Rep: Reputation: 0
Static ip


Hi,
I have my home network configured with DHCP (linux web server, 2 windows hosts) and now i want to have static ip adresses. My DHCP server is the router, not the linux server. How can i do that.

Thanks
 
Old 01-09-2008, 02:20 PM   #2
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
Quote:
Originally Posted by Supporter1984 View Post
Hi,
I have my home network configured with DHCP (linux web server, 2 windows hosts) and now i want to have static ip adresses. My DHCP server is the router, not the linux server. How can i do that.

Thanks
Based on information you supplied I'd say you have to edit some configuration file in your Linux box. If you tell us what distro you are using then we can tell you what file it is. If you have a GUI installed then there may be a GUI tool for this.
 
Old 01-09-2008, 02:32 PM   #3
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
On the Linux side of the world, you need to edit the file that contains the settings; it will be named something like inet1.conf or similar and will be in the directory containing your system's start up files in /etc. If you grep for the file name, there should be a pattern like DHCP_HOSTNAME in the file (you will need to disable that, by the way).

Here's an example of inet1.conf set up for fixed IP:
Code:
# This file contains the configuration settings for network interfaces.
# If USE_DHCP[interface] is set to "yes", this overrides any other settings.
# If you don't have an interface, leave the settings null ("").

# You can configure network interfaces other than eth0,eth1... by setting
# IFNAME[interface] to the interface's name. If IFNAME[interface] is unset
# or empty, it is assumed you're configuring eth<interface>.

# Several other parameters are available, the end of this file contains a
# comprehensive set of examples.

# =============================================================================

# Config information for eth0:
IPADDR[0]="192.168.1.20"
NETMASK[0]="255.255.255.0"
USE_DHCP[0]=""
DHCP_HOSTNAME[0]=""

# Config information for eth1:
IPADDR[1]=""
NETMASK[1]=""
USE_DHCP[1]=""
DHCP_HOSTNAME[1]=""

# Config information for eth2:
IPADDR[2]=""
NETMASK[2]=""
USE_DHCP[2]=""
DHCP_HOSTNAME[2]=""

# Config information for eth3:
IPADDR[3]=""
NETMASK[3]=""
USE_DHCP[3]=""
DHCP_HOSTNAME[3]=""
            
# Default gateway IP address:
GATEWAY="192.168.1.1"
<more stuff below this, nothing to do with fixed IP>
That is, the fixed IP address of the system is 192.168.1.20, the gateway address (the router) is 192.168.1.1 and the netmask is 255.255.255.0. You system will probably have values in the DHCP fields for eth0. Don't just copy the above, look for your file and read through any notes that may be in it. You may want to add your system name and the fixed IP address you've chosen (you may not want 192.168.1.20) in /etc/hosts.

On the Windows side of the world... well, can't really help your there but I run my Linux boxes fixed IP and a Windows (XP) machine as DHCP to the same router and it all works fine. Other than that, can't help you with Windows.

Hope this helps some.
 
Old 01-09-2008, 02:38 PM   #4
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
Cool, tronayne.

Here's the same for Gentoo:

Code:
 ~ $ cat /etc/conf.d/net

config_eth0=( "192.168.2.2 netmask 255.255.255.0 brd 192.168.2.255" )
routes_eth0=( "default gw 192.168.2.254" )
 
Old 01-09-2008, 06:52 PM   #5
Supporter1984
LQ Newbie
 
Registered: Jan 2008
Distribution: Slackware, Slax
Posts: 16

Original Poster
Rep: Reputation: 0
Thanks for the help so far. My distro is Slackware 12.

I have to change my router setting, am i right? I have to disable DHCP?

Last edited by Supporter1984; 01-09-2008 at 06:54 PM.
 
Old 01-09-2008, 07:02 PM   #6
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
No you don't. You may want to reserve some IP range for static addresses.
 
Old 01-09-2008, 07:06 PM   #7
Supporter1984
LQ Newbie
 
Registered: Jan 2008
Distribution: Slackware, Slax
Posts: 16

Original Poster
Rep: Reputation: 0
So you are saying that i dont need to disable the DHCP server. Do i have to have my static ip's on the DHCP ip range?

Thanks for the help.
 
Old 01-09-2008, 07:13 PM   #8
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
You have to have your static IP address on the same subnet. For instance, if you have net 192.168.1.0/24, (mask 255.255.255.0) then use static address 192.168.1.something.
 
Old 01-09-2008, 07:21 PM   #9
KnightHawk
Member
 
Registered: Aug 2005
Posts: 128

Rep: Reputation: 15
Quote:
Originally Posted by Supporter1984 View Post
So you are saying that i dont need to disable the DHCP server. Do i have to have my static ip's on the DHCP ip range?

Thanks for the help.
No, in fact you should remove them from the range. Or hard-code they're assignments with mac address.
 
Old 01-09-2008, 07:21 PM   #10
Supporter1984
LQ Newbie
 
Registered: Jan 2008
Distribution: Slackware, Slax
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Emerson View Post
For instance, if you have net 192.168.1.0/24,
What do you mean with that?
 
Old 01-09-2008, 07:30 PM   #11
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
Quote:
Originally Posted by Supporter1984 View Post
What do you mean with that?
That's a very good question. I recommend some reading: http://www.ipprimer.com/overview.cfm
 
Old 01-10-2008, 03:22 AM   #12
arubin
Senior Member
 
Registered: Mar 2004
Location: Middx UK
Distribution: Slackware64 15.0 (multilib)
Posts: 1,350

Rep: Reputation: 75
I have done this recently on Slackware.

You need to run netconfig as root and answer the questions.

On the router side you should be able to set it to limit the addresses it offers with dhcp. You then set your static IP outside this range.

Last edited by arubin; 01-10-2008 at 03:24 AM.
 
Old 01-10-2008, 03:32 AM   #13
arubin
Senior Member
 
Registered: Mar 2004
Location: Middx UK
Distribution: Slackware64 15.0 (multilib)
Posts: 1,350

Rep: Reputation: 75
A few more thoughts.

The way you do this depends on whether you want your router to offer dhcp to other machines or not. So you could set up static IP on your linux box and, when you are sure this is working turn dhcp off on the router.

An alternative approach is to the one I suggest in my earlier post. Restrict the range of addresses the router offers, up to for example 192.168.1.200 and set your static address for 192.168.1.201. The reason for restricting the range is to make sure that 192.168.1.201 is not given to another computer while yours is off.

Alternatively you set your router to always associate your PC with a particular address. You still connect to it dynamically with dhcp but the router always allocates the same address. This way you need to configure the router but do not need to change anything on the PC.
 
Old 01-10-2008, 08:19 AM   #14
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
The inet1.conf example I gave you above is from Slackware 12. If you have, say, a Linksys router, it by default starts DHCP addresses at 192.168.1.100; 192.168.1.2 through 192.168.1.99 can be used for fixed IP addresses (192.168.1.1 is the gateway address, don't fiddle with that). As suggested above, you can log in as root and use the netconfig to set this rather than manually editing inet1.conf

If you set your server to 192.168.1.10 you should be fine and your Windows machines will use 192.168.1.100, 192.168.1.101, etc. Don't forget that you'll need to reboot after making the changes (rebooting is the easiest way to have the setting take effect).

This assumes that you did not set your router to any other addresses or that it defaults to 192.168.1.X -- you may need to check that by pinging the address 192.168.1.0 for a response (and if you don't get one, use a browser to look at the router's settings referring to the manual that came with it).

It really is this easy, just edit inet1.conf (or run netconfig) and reboot.
 
Old 01-10-2008, 08:36 AM   #15
arubin
Senior Member
 
Registered: Mar 2004
Location: Middx UK
Distribution: Slackware64 15.0 (multilib)
Posts: 1,350

Rep: Reputation: 75
When I did this my main problems were with setting the gateway address and with setting the DNS address that the netconfig script offers. I think that in the end I found that it worked if I entered the same address as gateway for DNS. Until I got that right I could connect to the router but not to the Internet.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Making a static lib from objects + static libs kovacsp Programming 2 12-19-2007 12:53 PM
Howto Assign Multiple Static Public IP Addresses under SBC's PPPoE Static Ip system o trekgraham Linux - Networking 8 04-17-2007 10:51 AM
Java: non-static variable this cannot be referenced from a static context chief_officer Programming 4 05-29-2006 01:37 PM
Is there any static ARP for static IP network? linux_lover2005 Linux - Networking 2 05-18-2005 12:01 PM
FC2 Overriding static if in favor of dhcp system set for static pkraus109 Linux - Networking 8 09-21-2004 11:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration