LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 11-08-2004, 04:08 PM   #1
ninmonkeys
LQ Newbie
 
Registered: Nov 2004
Distribution: Slackware 10
Posts: 28

Rep: Reputation: 15
Using DHCP with a static IP


How do I set a static IP?

In windows I have it set up so I retrieve my information from my router which has a DHCP server, but I have a static lan ip.

In slackware 10, when it boots up, it gets its IP through the DHCP server fine, and I can browse the internet.

Here's the output If I try to set my IP, first check what the defaults were
Code:
[root@localhost: ~]$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:76:BF:09:AF  
          inet addr:192.168.1.107  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:21083 errors:0 dropped:0 overruns:0 frame:0
          TX packets:11013 errors:0 dropped:0 overruns:0 carrier:0
          collisions:1 txqueuelen:1000 
          RX bytes:10217021 (9.7 Mb)  TX bytes:1958944 (1.8 Mb)
          Interrupt:11 Base address:0xe400 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:2698 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2698 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2446512 (2.3 Mb)  TX bytes:2446512 (2.3 Mb)
[root@localhost: ~]$ ifconfig eth0 192.168.1.122
As soon as I type that, I am automatically disconnected from the internet. The only way I know how to get it back is to reboot. I tried eth0 up and eth0 down etc, but couldn't figure it out.

thanks,
--monkey
 
Old 11-08-2004, 04:16 PM   #2
level
Member
 
Registered: Jan 2004
Posts: 82

Rep: Reputation: 15
I not sure I completely understand what you want to do, but the static IP you are trying to use is a non-routable address and you can't connect to the internet with it. You can use it for your local area network.
 
Old 11-08-2004, 05:03 PM   #3
Skyline
Senior Member
 
Registered: Jun 2003
Distribution: Debian/other
Posts: 2,104

Rep: Reputation: 45
>> How do I set a static IP? <<

On Slackware you'd typically set up your ip address, mask and gateway in:

/etc/rc.d/rc.inet1.conf

and your nameserver addresses in

/etc/resolv.conf

That's sufficient for a connection, in addition to disabling the DHCP server option on your router - if you're going to disable the DHCP server option on the router just set up a static ip etc in Windows aswell.

Last edited by Skyline; 11-08-2004 at 05:07 PM.
 
Old 11-09-2004, 02:14 AM   #4
ninmonkeys
LQ Newbie
 
Registered: Nov 2004
Distribution: Slackware 10
Posts: 28

Original Poster
Rep: Reputation: 15
In windows, I get the DNS servers, etc, from my router, I didn't input them, but I have a static IP.

So in linux, do I need to get the information from my DHCP server, then disable dhcp, and set all the settings manually?

What is the ifconfig command to do that? Say my ip is 192.168.1.122 and my router is 192.168.1.100 (This might be called gateway in windows, the IP of my router)
 
Old 11-09-2004, 02:33 AM   #5
cidrolin
Member
 
Registered: Jul 2004
Distribution: Fedora c2
Posts: 89

Rep: Reputation: 15
the reason why you lost web access after changing the IP address of you eth0 (using ifconfig) is that the route to the default gateway was erased in the process. To regain access, you must do :
Code:
route add default gw ip_of_your_router eth0
To get your static address at boot-time, you must change the network settings for eht0, either using a GUI tool or by editing the config file. I don't know which it is for Slackware; fyi, on a FC2 the path to the file woulo be /etc/sysconfig/networking/devices/ifcfg-eth0.
 
Old 11-09-2004, 05:32 AM   #6
knutove1728
Member
 
Registered: Oct 2004
Location: Norway
Distribution: Redhat FC2
Posts: 44

Rep: Reputation: 15
In rc.local type /sbin/ifconfig eth0 x.x.x.x netmask=x.x.x.x up
x is your static ip address. Check the syntax (man ifconfig) for netmask. I'm uncertain if you should use = or not.
In ifcfg-eth0 set BOOTPROTO=none
You can also add the route command in rc.local as described by cidrolin to be sure it find the route at boot.
 
Old 11-09-2004, 08:11 AM   #7
Skyline
Senior Member
 
Registered: Jun 2003
Distribution: Debian/other
Posts: 2,104

Rep: Reputation: 45
Quote:
So in linux, do I need to get the information from my DHCP server, then disable dhcp, and set all the settings manually?
You've got a choice - either get the information via DHCP from the router or assign the information manually - presumably you already know your gateway ip aswell as your chosen static ip, you're netmask will be 255.255.255.0 - in Slackware you can use this file, /etc/rc.d/rc.inet1.conf to set up the relevant information - as an example with a gateway of 192.168.0.1, an ip of 192.168.0.2 and the corresponding mask:

(Part of a /etc/rc.d/rc.inet1.conf file with example values used)

Code:
# Config information for eth0:

IPADDR[0]="192.168.0.2"
NETMASK[0]="255.255.255.0"
USE_DHCP[0]=""
DHCP_HOSTNAME[0]=""

# Default gateway IP address:

GATEWAY="192.168.0.1"
If you have a look at /etc/rc.d/rc.inet1.conf you'll see the sections to fill in similar to the above - for your nameserver addresses simply use /etc/resolv.conf.

Last edited by Skyline; 11-09-2004 at 08:22 AM.
 
Old 11-09-2004, 08:32 AM   #8
mikedeatworld
Member
 
Registered: Nov 2003
Location: Farmington Michigan
Distribution: UBUNTU - Slackware - SuSE 9.1 - Knoppix - Fedora
Posts: 828

Rep: Reputation: 30
Your router will mostly likely give your machine an 192.xxx.xxx.xxx non-routable IP address.

Why do you not want to use the IP you obtained from your router?


You will still be able to communicate with your LAN?
 
Old 11-09-2004, 02:09 PM   #9
ninmonkeys
LQ Newbie
 
Registered: Nov 2004
Distribution: Slackware 10
Posts: 28

Original Poster
Rep: Reputation: 15
1) So say I normally use DHCP, but I now need to change to a certain IP, you're saying
Code:
$ ifconfig eth0 192.168.1.122
$ route add default gw 192.168.1.1 eth0
And I'd be back on the net, with my lan IP being 192.168.1.122?

2) I have entries in /etc/resolv.conf but I didn't put them there. If I disable DHCP, will they dissapear? (I'm asking because how else did they get there?)

Quote:
Your router will mostly likely give your machine an 192.xxx.xxx.xxx non-routable IP address.

Why do you not want to use the IP you obtained from your router?
3)What doyou mean non-routable IP?

The way it is now, I get a random lan IP 192.168.1.xxx (first 3 numbers are always the same) I sometimes want a static, or at least the ability to change my IP (question #1) because my router will route ports to a certain IP. If I don't change my IP, I will have to change several entries everytime I want to host a game/use bittorent/etc.
 
Old 11-30-2004, 07:32 AM   #10
anon259
LQ Newbie
 
Registered: Nov 2004
Location: London
Posts: 1

Rep: Reputation: 0
i also face the same...

Hi guys,

I was trying to run a public FTP server from my LAN.... my ISP gives me a public IP address which is actually assigned to my router cum switch.... the broadband router gives me a DHCP address.... which may change each time I turn on the machine. I want to keep it static so that I can assign my IP in the router's port forwarding configuration.

I tried doing it from Windows... its working perfectly.... but in linux... I am not able to access anything outside my LAN... unless I configure it as a DHCP client.

I use fedora core 2..

Please help me out.

Cheers
 
  


Reply



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
From DHCP to static IP. dave`2005 Slackware 3 08-22-2005 09:12 AM
FC2 Overriding static if in favor of dhcp system set for static pkraus109 Linux - Networking 8 09-21-2004 11:13 AM
DHCP to static IP ?? davepal Linux - Networking 1 04-21-2004 09:34 AM
How to Chage from DHCP to static jamescov Linux - Networking 2 11-13-2003 08:48 PM
DHCP or Static Culbert Linux - Networking 1 03-14-2003 07:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:19 AM.

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