Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-08-2004, 04:08 PM
|
#1
|
LQ Newbie
Registered: Nov 2004
Distribution: Slackware 10
Posts: 28
Rep:
|
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
|
|
|
11-08-2004, 04:16 PM
|
#2
|
Member
Registered: Jan 2004
Posts: 82
Rep:
|
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.
|
|
|
11-08-2004, 05:03 PM
|
#3
|
Senior Member
Registered: Jun 2003
Distribution: Debian/other
Posts: 2,104
Rep:
|
>> 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.
|
|
|
11-09-2004, 02:14 AM
|
#4
|
LQ Newbie
Registered: Nov 2004
Distribution: Slackware 10
Posts: 28
Original Poster
Rep:
|
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)
|
|
|
11-09-2004, 02:33 AM
|
#5
|
Member
Registered: Jul 2004
Distribution: Fedora c2
Posts: 89
Rep:
|
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.
|
|
|
11-09-2004, 05:32 AM
|
#6
|
Member
Registered: Oct 2004
Location: Norway
Distribution: Redhat FC2
Posts: 44
Rep:
|
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.
|
|
|
11-09-2004, 08:11 AM
|
#7
|
Senior Member
Registered: Jun 2003
Distribution: Debian/other
Posts: 2,104
Rep:
|
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.
|
|
|
11-09-2004, 08:32 AM
|
#8
|
Member
Registered: Nov 2003
Location: Farmington Michigan
Distribution: UBUNTU - Slackware - SuSE 9.1 - Knoppix - Fedora
Posts: 828
Rep:
|
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?
|
|
|
11-09-2004, 02:09 PM
|
#9
|
LQ Newbie
Registered: Nov 2004
Distribution: Slackware 10
Posts: 28
Original Poster
Rep:
|
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.
|
|
|
11-30-2004, 07:32 AM
|
#10
|
LQ Newbie
Registered: Nov 2004
Location: London
Posts: 1
Rep:
|
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
|
|
|
All times are GMT -5. The time now is 05:11 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|