Do I just need to change dhcpcd.conf to get a static IP?

I have two Pi systems on my LAN here at home, one just provides DNS using dnsmasq and the other has a big external USB drive for backups.

The DNS Pi has a static IP of 192.168.1.2.

If the DNS Pi dies I want to quickly configure the backup Pi to provide DNS. The main thing required for this to work is to give it a static IP of 192.168.1.2 and to configure dnsmasq on it.

Copying the dnsmasq configuration across is easy enough, I can simply synchronise /etc/dnsmasq.conf and /etc/dnsmasq.d between the two systems and that's done. As long as I don't actually run dnsmasq on the backup machine all will be well.

So, if/when the DNS Pi dies all I need to do is:-

Configure the backup machine to have a static IP of 192.168.1.2

Copy the dnsmasq.leases file (I'm keeping a live copy of that)

Start dnsmasq

Simple! :-)

Is the configuration in /etc/dhcpcd.conf *all* that's needed for a static IP?

--
Chris Green
Reply to
Chris Green
Loading thread data ...

I'm always cautious of configuring any computer with a static IP address in the device's TCP configuration. It's all too easy to move a portable device onto a different LAN where the static IP may either be in the wrong subnet or may be within the scope of the LAN's DHCP server and so may, when Sod's Law is in operation, give another device the same address.

Instead, I configure the router to allocate a reserved address (as an IP-to-MAC address mapping) for the devices that I want to have a "static" address. Most modern routers seem to allow reserved IPs to be configured. There is no need for the reserved addresses to be outside the scope of addresses that DHCP hands out.

So you are using DHCP in exactly the same way as a normal (random-IP) setup, but forcing the router's DHCP to give certain devices fixed addresses.

In your situation where you want either the main or the backup Pi to have the same IP, you could achieve this by tweaking the router's reserved addresses. Whether it's easier/harder than reconfiguring the static IP at the backup Pi's TCP settings - well, that's debateable :-)

Reply to
NY

If your network is set up by systemd, see the directory /etc/systemd/network. There is a setup file, see man systemd.network.

If the network is set up the traditional way, see the directory /etc/network/interfaces.d. The setup file interfaces is described in man 5 interfaces.

--

-TV
Reply to
Tauno Voipio

In article (Dans l'article) , Tauno Voipio

On my RPi, I get :

pi@raspberrypi:~ $ ls -al /etc/network/interfaces.d total 8 drwxr-xr-x 2 root root 4096 jan 30 2017 . drwxr-xr-x 7 root root 4096 nov 9 2020 ..

pi@raspberrypi:~ $ ls -al /etc/systemd/network total 8

drwxr-xr-x 5 root root 4096 sep 13 12:43 ..

pi@raspberrypi:~ $ uname -a Linux raspberrypi 5.10.60-v7+ #1449 SMP Wed Aug 25 15:00:01 BST 2021 armv7l GNU/Linux

--
Jean-Pierre Kuypers
Reply to
Jean-Pierre Kuypers

Er, the Pi in quation is also the DHCP server! That's the point, it's how it gets to know the LAN systems' names.

--
Chris Green
Reply to
Chris Green

One more try: /etc/dhcpcd.conf. In some set-ups, it seems to control static addresses, too.

--

-TV
Reply to
Tauno Voipio

I use an even simpler approach to maintain:

I run named to provide a DNS service for my LAN, partly because its easier to maintain a single central zone file for my LAN than to keep resolv.conf files in sync on all systems on the LAN that need this info and partly because I could and anyway I wanted to understand the care and feeding of a DNS.

/etc/systemd/resolved.comp is the same on all computers: the IPs listed in the DNS= and FallbackDNS= lines are:

DNS= my_local_DNS my_ISP's_DNS_resolver FallbackDNS= My network supplier's DNS resolvers

This file should never need to be modified and is the same on all my computers.

--
--   
Martin    | martin at 
Gregorie  | gregorie dot org
Reply to
Martin Gregorie

There are two ways a DHCP server gets to know the LAN systems' names. Many (not all) systems send the hostname as part of the DHCP request, this can be used to updated DNS (trivially easy with dnsmasq, more fiddly otherwise). With dnsmasq it is also possible to specify a name for a MAC address and have it assigned in the DNS to the dynamic or fixed IP address issued by dnsmasq. Similar things are possible with other DHCP and DNS servers but usually the only easy thing is to issue a fixed IP address corresponding to a fixed DNS entry.

--
Steve O'Hara-Smith 
Odds and Ends at http://www.sohara.org/
Reply to
Ahem A Rivet's Shot

Yes, exactly! It's why I use dnsmasq as the DNS and DHCP server on my LAN. Most systems supply a name when getting their IP from the DHCP server so as a result most systems on my LAN can be called by name with no extra effort needed from me. A few systems that don't provide names as you say can be given names in dnsmasq.conf .They're mostly things like Freeview boxes, a Roku streaming box and an Onko amplifier, still it's nice to give them names so otherwise anonymous devices can be identified as "meant to be there".

--
Chris Green
Reply to
Chris Green

But this doesn't give you names for the systems on your LAN does it?

I want to be able to ssh freely from desktop (name esprimo) to laptop (name t470) to Pi (dns) to another Pi (backup) to my wife's laptop (x201), etc. Running dnsmasq as DHCP/DNS server provides me with this ability easily.

--
Chris Green
Reply to
Chris Green

The canonical way is to run BIND9 and link it with the dhcp server, which may or may not run on the same machine. You set the static addresses in dhcpd.conf and they will be transferred to BIND. There is an encryption key held in common.

Yes, a lot of people like something simpler, but I run a mixed network, and BIND works with anything, even the wretched Windows. It is, after all, the reference *nix DNS server.

Note that while dhcp can push many types of information, including hostnames, the client has no obligation to use any of it.

--
Joe
Reply to
Joe

You can do it all with other DNS and DHCP servers but you have to put all the glue in place yourself which is a RPITA, dnsmasq makes it wonderfully easy. If only it had good failover support (that's hard).

There's an even cooler trick it can do if you have IPv6, you can get it to do the router advertisements and notice when a SLAAC address embeds the same MAC as a DHCP lease and assign the IPv6 SLAAC address to the name. I don't know anything else that does this.

Exactly why I bother to do the same thing.

--
Steve O'Hara-Smith 
Odds and Ends at http://www.sohara.org/
Reply to
Ahem A Rivet's Shot

The easy way (that admittedly is less scalable and less robust - no failover options) is to use dnsmasq for both.

As does dnsmasq. Standards are wonderful things they encourage multiple implementations with differing characteristics. My home network has three flavours of unix, Mac OS, Android, ChromeOS, IOS, Windows and whatever various TVs, dongles and games consoles run. All perfectly happy with dnsmasq being the DNS, DHCP and router advertisement server.

I wouldn't use dnsmasq for a corporate name server and these days I wouldn't use bind for a home network (I used to).

--
Steve O'Hara-Smith 
Odds and Ends at http://www.sohara.org/
Reply to
Ahem A Rivet's Shot

Yes it does: the name is linked with the IP when you add the new system to the zone file: the resolved.conf file directs name searches to your DNS first, so the enquirer gets handed the correct IP by your local DNS: if the query fails its a fair assumption that the name doesn't belong to one of your local machines, and the systemd resolver then asks the external DNSs listed in your resolved.conf file.

I assume that you'll you've given each new system it's name when you first configured it, but I don't think that affects much apart from allowing the system to realise that the connection request can be satisfied without bothering any DNS.

That's exactly what I do: any machine on my LAN can connect to any other machine on it because my local DNS resolves all names with of the form localsystemname.localdomain.lan - localdomain.lan being the zone it is configured to resolve names in.

Initially, setting up named needed a little head scratching, but I found "DNS and BIND" (O'Reilly) useful, but it doesn't cover the unbound resolver, so other books may relevant too. It may be worth noting that, apart from adding and deleting machines as my LAN system population changes, my named configuration hasn't needed to change for many years.

--
--   
Martin    | martin at 
Gregorie  | gregorie dot org
Reply to
Martin Gregorie

On Tue, 28 Sep 2021 15:29:23 +0100, "NY" declaimed the following:

Something that looks rather simple in my ATT U-Verse (ARRIS) router.

""" To create an IP Allocated client select the Allocate button next to the client. The IP Allocation Entry section appears. Choose a Fixed address for the client and click "Save".

To change an IP Allocated client back to a normal DHCP client select it and click "Allocate". Then in the IP Allocation Entry section select "Address from DHCP pool" and click "Save". """ Might require first converting the failed unit back to dynamic (this router splits the LAN into an fixed pool and a DHCP pool), before changing the secondary to fixed IP.

--
	Wulfraed                 Dennis Lee Bieber         AF6VN 
	wlfraed@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/
Reply to
Dennis Lee Bieber

Right but you have to edit the zone file - it is possible to have the name supplied as part of the DHCP query added to the DNS for the LAN with no intervention so that new hosts added to the network get a name in the DNS without having to edit a zone file.

--
Steve O'Hara-Smith 
Odds and Ends at http://www.sohara.org/
Reply to
Ahem A Rivet's Shot

Yes, that's right. Using dnsmasq a new system plugged into the LAN gets assigned an IP by dnsmasq and (assuming it gives dnsmasq its name which Linux systems, including Pis, do) you can then use the name to access the new system without any extra configuration.

--
Chris Green
Reply to
Chris Green

I have internet access via Orange Belgium. I have configured the DHCP on the modem (router) with mac addresses and ip adresses, and so I always got same ip adresses for my computers. Just info, depend of your environment.

Reply to
zeneca

Re: Re: Do I just need to change dhcpcd.conf to get a static IP? By: Joe to zeneca on Fri Oct 01 2021 10:02 am

Maybe I am pushing my nose where it is not wanted, but I have found that Mikrotiks work very well for home environments and small offices. They are pretty much consumer-grade hardware running enterprise firmware, so you can do a lot of stuff with them.

Even some of the cheapo models have _separated_ logic so you put the effort of filtering packets on the switches or move it to the CPU at your convenience.

If that is not your thing, many people just gets some SOHO junk and places OpenWRT in it for a nice effect.

--
gopher://gopher.richardfalken.com/1/richardfalken
Reply to
Richard Falken

And over the years, many of us have been let down by domestic-grade routers, sometimes in subtle ways. Few of us can afford industrial Cisco kit or the like.

I once used a router for DNS to gain caching from my ISP. One day, after a couple of frustrating hours, I found it was failing to return the occasional MX (always the same ones). My BIND was immediately switched to root hints, less efficient but I know it works every time.

I had one router (several actually) which needed a reboot occasionally, so I made a small cron script to do it when needed. Thanks to the vagaries of router signal handling, I ended up checking up to six Net sites in round-robin, and actually parsing some returned characters from each one. I couldn't find anything less that would reliably detect the need to reboot.

So I run BIND9 on root hints, even on my venerable Pi2. It works almost perfectly, except for the Pi apt repository site, which sometimes needs a couple of tries to get DNS results during update.

--
Joe
Reply to
Joe

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.