[SOLVED] Having internet with USE_DHCP="" in rc.inet1.conf possible?
SlackwareThis Forum is for the discussion of Slackware Linux.
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.
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.
I'll try first doing it the simple way, as TobiSGD says and, if I succeed, I will then do it as allend says (1). So, if I understood well, I must do
IPADDR[0]="192.168.0.2" #Example
NETMASK[0]="255.255.255.0"
USE_DHCP[0]="yes"
GATEWAY="<the IP the modem gets from the ISP>
However, I've already done this and it did not work, but I'll do it again. That is, I will have internet, but the IP of this machine won't be 192.168.0.2.
By the way, what do you mean "set the router as gateway", TobiSGS? Anything to do with GATEWAY=?
If all you want is a static IP on your machine while being able to access the internet through your modem, you only need to set up 3 things manually while disabling DHCP:
the desired IP/netmask combination;
the gateway, that must point to the modem local IP (not the WAN IP assigned by the ISP) e.g. 192.168.0.1;
the DNS, that can be set to the modem local IP too to use the DNS configured on the modem
While the first two settings can be set in the /etc/rc.d/rc.inet1.conf file, the last one needs an appropriate "nameserver [IP]" entry in the /etc/resolv.conf file.
Keep in mind that if you switch again to using DHCP without telling it to keep the resolv.conf file as-is, it will be overwritten.
Now you are finding out why DHCP will ultimately be better and easier. DHCP handles the gateway, network mask and name resolution stuff automatically.
The gateway address is the LAN IP address of your router, probably 192.168.0.1
IPADDR[0]="192.168.0.2" #Example
NETMASK[0]="255.255.255.0"
USE_DHCP[0]="yes"
GATEWAY="<the IP the modem gets from the ISP>
No, as several times pointed out already, you do not use DHCP and static IPs on the same machine at the same time. And you do not set the gateway IP to the IP the the modem gets from your ISP. This IP is on the side of your network that face the Internet, not your local net.
See this example:
Code:
PC1 (IP: 192.168.0.100)--
|
--- Router (IP: 192.168.0.1 on local net, set by DHCP on the Internet side by the modem) --- Modem (IP: DHCP from ISP)
|
PC2 (IP: 192.168.0.101)--
In this example you would set the gateway address on both PCs to 192.168.0.1, the address of the router that is facing towards you local network. The Other IP addresses are irrelevant for you.
Quote:
Originally Posted by allend
I do not recommend doing this. Setting up DHCP correctly will pay dividends in the future. It will make adding additional devices to your LAN much easier.
Quote:
Now you are finding out why DHCP will ultimately be better and easier. DHCP handles the gateway, network mask and name resolution stuff automatically.
Easier in larger networks, yes, I agree. In small (home) networks the approach with static IPs is much easier, especially if the machines should communicate with each other. Of course you can go for a mixed approach (I do that on my network), where machines that are always there get a static IP, but the router is still offering DHCP for temporary connections and machines that don't have to communicate with each other in a simple way.
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680
Rep:
I'm in agreement with allend here, as I mentioned in the other thread. Leave the machines as DHCP and use the simple web interface of your router to give them static IP addresses.
There's just a small thing that's not quite clicking that's making this seem a lot more complicated than it is.
This looks like it might describe what's going on: http://networking.nitecruzr.net/2005...at-router.html
You could also google "NAT Router" but some of the explanations are long-winded and take in more cases than the simple home network.
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
I use a setup similar, I think, to what you're trying to do; maybe this will help (and, well, maybe not but here goes).
I've had DSL and now satellite service. The ISP provides a modem or modem/router that typically is DHCP -- you connect a computer to it (say a Windows machine) and away you go (Windows machines all default to DHCP). Typically, the modem has an address such as 192.168.0.1 or 192.168.1.1; that is you gateway (to the internet) address. The other side of the modem, the Internet side, has the address assigned to you by the ISP server which will vary every time the modem is turned off for a while then turned back on (that's what DHCP does at the ISP end, it "leases" an address to your modem at power up).
On your side of the modem, when you power up a computer, the modem's DHCP assigns an address to your connection, something like 192.168.1.100 (and these addresses can vary, but they'll never be 192.168.0.1 or 192.168.1.1, the gateway address).
Now, you want to connect multiple devices to your Internet connection; computers, printers, TV set-top, whatever, and you want it wired (or maybe wired and wireless, who knows). So, you get yourself, oh, say a 4-port router.
What the router gives you is route for your devices to talk to each other and to the Internet. You can do this with either DHCP or fixed-IP, both of which require a little bit of configuration so everybody knows who they are and who everybody else is (think telephone numbers here, might make it easier).
When you installed Slackware you were questioned about setting up your network; you gave each system a name and a domain (maybe). If you chose DHCP, you were all done; however, if you chose fixed-IP, you were prompted to enter addresses.
Here's the trick: DHCP (in the router) will usually start leasing at 192.168.1.100 (or something like that, it won't start at 192.168.1.2). That means that you can specify the address of each device from 192.168.1.2 through 192.168.1.99 -- pretty neat, huh? And, wonder of wonders, the router will handle that just fine. You don't need to set anything in the router for this to work -- well, you do have enable DHCP in the router if it isn't enabled by default, but you don't have to list server addresses in there.
My in-house systems are fixed-IP (I prefer it that way). When I execute netconfig (the Slackware utility you set up you network with), I give a name, an address, netmaksk, gateway address and a DNS address. Those are saved in /etc/rc.d/rc.inet1.conf and look like this:
Code:
# Config information for eth0:
IPADDR[0]="192.168.1.10"
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"
The netconfig utility saves the system name and address in /etc/hosts like this:
Code:
192.168.1.10 fubar.com fubar
(I gave it "fubar" as the name, "com" as the domain and I manually add the alias "fubar" so I don't have to type "fubar.com" to connect to the server from another server).
Simple? Yup. My /etc/hosts file (on every server) looks like
Code:
# For loopbacking.
127.0.0.1 localhost
# Local servers
192.168.1.10 fubar.com fubar
192.168.1.15 InkJet
192.168.1.20 snafu.com snafu
192.168.1.30 pita.com pita
# Public servers
75.126.162.205 www.linuxquestions.org linuxquestions.org
74.125.224.70 maps.google.com
74.125.224.111 maps.gstatic.com
# End of hosts.
Those "Public Servers" in there? Those are so there is no DNS look up for their addresses, /etc/hosts entries are the first place looked at before DNS is invoked. It's quicker.
Can you do this same thing with DHCP? Of course.
This link, http://www.linuxquestions.org/questi...9/#post4826521, will take you a example of a working DHCP network configuration (with thanks to @kikinovak, a pretty smart guy). As you scan though it you'll see that device names and addresses are assigned and DHCP (in the router) will honor those.
The important thing is that devices configured with fixed-IP or DCHP (as described) can find each other (so you can do stuff like use scp between them without fooling around).
Now, you can plug a Windows box into your router and it'll work (to the Internet anyway) because the router will give it a lease at 192.168.1.100 or so and that will not interfere with your configured device addresses. Pretty slick.
If all you want is a static IP on your machine while being able to access the internet through your modem, you only need to set up 3 things manually while disabling DHCP:
the desired IP/netmask combination;
the gateway, that must point to the modem local IP (not the WAN IP assigned by the ISP) e.g. 192.168.0.1;
the DNS, that can be set to the modem local IP too to use the DNS configured on the modem
While the first two settings can be set in the /etc/rc.d/rc.inet1.conf file, the last one needs an appropriate "nameserver [IP]" entry in the /etc/resolv.conf file.
Keep in mind that if you switch again to using DHCP without telling it to keep the resolv.conf file as-is, it will be overwritten.
I did the three things in both machines, plus the /etc/hosts thing, and the result was: (a) I have internet in both machines. (b) I can slogin from machine A into machine B. (c) I CANNOT slogin from B into A. When I try I get:
Code:
ssh: connect to host SERVER_HOST port 22: no route to host.
However, while in B ifconfig gives inet=192.168.0.3, which is fine, in B it gives inet=192.168.0.100 I can't understand why. I should be inet=192.168.0.2.
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
If you're using static addresses, fixed-IP, add all devices to the /etc/hosts file on all machines, then they can find each other.
Oh, yeah, when you change network settings it's a good idea to reboot the machine you changed 'em on (if you didn't already do that). You don't need to reboot any others.
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
On that box run netconfig. Give it name, domain, netmask (the default ought to OK), address is 192.168.0.2, gateway is 192.168.0.1, DNS, oh, 8.8.8.8 (that's Google's DNS server). Review the settings on the page that pops up and exit netconfig.
netconf wipes out /etc/hosts, so edit in the other machine(s) names and addresses.
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680
Rep:
Quote:
Originally Posted by TobiSGD
Easier in larger networks, yes, I agree. In small (home) networks the approach with static IPs is much easier, especially if the machines should communicate with each other. Of course you can go for a mixed approach (I do that on my network), where machines that are always there get a static IP, but the router is still offering DHCP for temporary connections and machines that don't have to communicate with each other in a simple way.
DHCP on most home routers gives the ability to hand out specific IP addresses to specific machines every time.
This is, I find, quicker to set up than setting a fixed IP on each machine individually and means that if machines are taken from your network and plugged into a new network they'll likely start to work there too. It also leaves the rest of the DHCP range for any new devices you introduce.
Of course host file entries still need adding for other machines on the network but that should be easier to explain one the router settings have been seen.
Personally, that is how I would solve this particular problem. That and some reading of the principals involved.
Perhaps it's just me but using manually configured fixed IP addresses seems a little "old fashioned" and long-winded?
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
Most routers that I've fiddled with tend to lose their little minds doing DNS (maybe that's changed, but I dunno) -- for some reason or other they stop serving DNS after a period of time and I find it more useful to simply put entries in /etc/resolv.conf. At least the one's I have do that.
You ISP ought to provide one or two DNS addresses or you can use Google's freebies (8.8.8.8 and 8.8.4.4) and your /etc/resolv.conf ought to look like this:
Code:
cat /etc/resolv.conf
search com
nameserver 68.94.156.1
nameserver 68.94.157.1
# Google Free DNS Servers
#nameserver 8.8.8.8
#nameserver 8.8.4.4
# HughesNet DNS Servers
#nameserver 66.82.4.8
#nameserver 66.82.4.12
The first two are ISP-provided, the others are commented out but available if the first two go away for some reason (and they then will be commented out or deleted).
You only need two; if the first on the list is dead, you'll sit there for quite a while waiting for the timeout to switch to the second (and so on if you have more).
Trick is, ping the addresses and select the one that's the fastest to be first.
Honestly, I don't understand well this DNS subject. One thing I know is that I do not have BINDS activated. Neither dnsmasq. I thought that in /etc/resolv.conf I have to put the IP of the gateway, which is 192.168.0.1 in my case, according to the route command.
On the other hand, I have two workarounds to momentarily solve this problem: One is to put the line
ifconfig eth0 192.168.0.2
in /etc/rc.d/rc.local, so it executes each time the system boots. The other, and the one I chose, given that the ifconfig command insists in tell me that my ip address is 192.168.0.100, is to choose this ip for this machine. Doing this, all works fine. But I do not know why I can't choose an arbitrary ip in the range 192.168.0.0 192.168.0.254.
One thing I know is that I do not have BINDS activated. Neither dnsmasq. I thought that in /etc/resolv.conf I have to put the IP of the gateway, which is 192.168.0.1 in my case, according to the route command.
So, if I understand you put in /etc/resolv.conf as nameserver the IP address of your gateway, where there is no nameserver
Last edited by Didier Spaier; 02-19-2013 at 11:12 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.