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 |
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.
|
 |
07-02-2017, 09:23 AM
|
#1
|
Senior Member
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127
Rep: 
|
How often does a computer need to access a DHCP server?
This might belong in networking but it is so simple (I should know the answer but don't) that I am posting it here...
I have a PC setup as a VPN sharing box and a DHCP server. A few minutes ago I took the box down to do a semi-annual backup image of the drive. I realize that this would kill my Internet access until it was back on line and connected to the VPN provider. No problem. However...
When I place the box back in operation I found that my PC could not connect to it. ifconfig on the PC showed NO IP address on the Ethernet NIC. The NIC is configured to get its IPv4 address by "Automatic (DHCP)". Stopping and starting the Ethernet connection of course brought back the IP address to the PC. Which makes me wonder...
I understand that a DHCP server issues an IP address with a "lease time" perhaps an hour. During that time if the recipient of the IP address drops off the network and then returns the recipient will get that same address. After the lease period the recipient might find that the address has been given to a different requester. That is well and good. However, why does the recipient forget its assigned address while it is still connected to the network and the DHCP server is temporarily down?
TIA,
Ken
|
|
|
07-02-2017, 09:35 AM
|
#2
|
Senior Member
Registered: Dec 2014
Location: Montreal, Quebec and Dartmouth, Nova Scotia CANADA
Distribution: Arch, AntiX, ArtiX
Posts: 1,364
|
Hi Ken,
Since you say that bringing down your DHCP server for maintenance would interrupt Internet access, could it be that the computer you are using as a DHCP server is also the default gateway (your description of your setup seems to suggest this ...) ? If a client computer loses its default gateway, it might behave the way you have described.
Cheers,
Last edited by Rickkkk; 07-02-2017 at 09:36 AM.
|
|
|
07-02-2017, 10:25 AM
|
#3
|
Senior Member
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127
Original Poster
Rep: 
|
Thanks Rickkkk,
Yes, the DHCP box is also the default gateway. However, it is my understanding that the gateway is necessary to connect to a different subnet. For example, my LAN is on 10.42.0.nnn. In its gateway role the DCHP box will route traffic to the VPN network (e.g. 162.210.192.159).
If I hard code an address into two machines on my LAN on 10.42.0.nnn and plug them into a switch they should be able to talk to each other without benefit of a gateway. Perhaps I will try that and see what happens.
Ken
|
|
|
07-02-2017, 12:22 PM
|
#4
|
Member
Registered: May 2013
Posts: 89
Rep: 
|
Quote:
Originally Posted by taylorkh
why does the recipient forget its assigned address while it is still connected to the network and the DHCP server is temporarily down?
|
I expect the DHCP lease expired, during that "temporary" period. So, could consider it bad timing.
However, there's different ways that DHCP clients can operate. I reckon the 3 main client strategies, in order of complexity, are:
Do a DHCP lookup & get a connection at bootup, then:
1. Forget about DHCP, i.e. don't monitor DHCP further.
2. At lease expiry time, ask for a DHCP update, and check for changes.
3. Set the IP configuration to timeout (as shown by "ip addr" on the Linux client), and require a DHCP update at every lease expiry.
I'd say that option 3 would usually be needlessly excessive.
|
|
|
07-02-2017, 02:22 PM
|
#5
|
Senior Member
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127
Original Poster
Rep: 
|
Thanks brebs,
ip addr showed
Code:
2: enp0s31f6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 48:4d:7e:e7:bd:1b brd ff:ff:ff:ff:ff:ff
inet 10.42.0.120/24 brd 10.42.0.255 scope global dynamic enp0s31f6
valid_lft 586sec preferred_lft 586sec
inet6 fe80::4a4d:7eff:fee7:bd1b/64 scope link
valid_lft forever preferred_lft forever
This was just after bringing up the Ethernet connection so I suspect the time period in question is 10 minutes or 600 seconds.
What I SHOULD have done instead of setting up a DHCP server (it was too much fun and a good learning experience :-) was to hard code the IP address in each of my handful of machines. I have IP addresses for each device specified in the DHCP configuration and I have a /etc/hosts file on each machine for machine to machine lookup. I configured the IP manually on the machine from which the above example produced. ip addr now shows
Code:
2: enp0s31f6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 48:4d:7e:e7:bd:1b brd ff:ff:ff:ff:ff:ff
inet 10.42.0.120/24 brd 10.42.0.255 scope global enp0s31f6
valid_lft forever preferred_lft forever
inet6 fe80::4a4d:7eff:fee7:bd1b/64 scope link
valid_lft forever preferred_lft forever
I tested by manually configuring a second machine then unplugging the DHCP server from the LAN. The two machines could communicate fine and their IP addresses did not disappear. I will leave the DHCP server running for some occasionally used virtual machines and manually configure the physical machines. That would appear to be a SIMPLE answer.
Thanks again,
Ken
|
|
|
07-02-2017, 03:11 PM
|
#6
|
Member
Registered: May 2013
Posts: 89
Rep: 
|
That's 3 bad things:
* Very short DHCP lease timeout
* A DHCP client which adds the lease expiry to the IP address
* Unnecessary use of ipv6, which is easy to fix, with e.g. "options ipv6 disable_ipv6=1" in /etc/modprobe.d/call-it-whatever.conf
|
|
|
07-02-2017, 03:11 PM
|
#7
|
Senior Member
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,950
|
If you buy one additional machine, you will have to update all your existing machines.
Good luck if you want to access your wifi connection on your mobile.
BTW I've set my DHCP lease time to 24 hours. 
|
|
|
07-04-2017, 02:56 AM
|
#8
|
Senior Member
Registered: Apr 2010
Posts: 2,288
|
Quote:
Originally Posted by taylorkh
Thanks Rickkkk,
Yes, the DHCP box is also the default gateway. However, it is my understanding that the gateway is necessary to connect to a different subnet. For example, my LAN is on 10.42.0.nnn. In its gateway role the DCHP box will route traffic to the VPN network (e.g. 162.210.192.159).
If I hard code an address into two machines on my LAN on 10.42.0.nnn and plug them into a switch they should be able to talk to each other without benefit of a gateway. Perhaps I will try that and see what happens.
Ken
|
For the machines to communicate between each other you need to have a router, a switch is unable to route packets unless of course it is a smart switch that supports routing.
If your DHCP box is a Linux box. You can temporarily create the DHCP on your router, is this for your home network or office network?
Whatever network it is just purchase a cheap router and make it as a DHCP server while taking down your current DHCP. Make sure of course that all configuration is the same especially the IP Address that is lease to the network. I think users won't be able to able to tell that current DHCP is down, if another DHCP is ready to take the role.
Good luck!
|
|
|
07-04-2017, 07:46 AM
|
#9
|
Moderator
Registered: Aug 2002
Posts: 26,644
|
For two devices to communicate with each other using static IP addresses on the same LAN/subnet all you need is an ethernet cable connecting them together.
With many current distributions the network adapters and the DHCP client are controlled by NetworkManager. As stated there could be several reason why it might loose its IP address. Without knowing anything about your network configuration a fourth reason might be that NetworkManager sensed eth0 lost link.
I have never tried but you could (assuming your systems are using dhclient) preload a static IP lease. I've never tired it and do not know if it works with NetworkManager.
|
|
|
07-04-2017, 10:56 AM
|
#10
|
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 11,147
|
Most home routers provide DHCP services in addition to routing. If your computer got its DHCP assignment from the router, then the router always knows where your computer (MAC Address) is.
DHCP assignments are called "leases" and they do customarily have a timeout period after which they are renewed through automatic re-negotiation with the server.
|
|
|
All times are GMT -5. The time now is 07:44 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
|
|