Distributor ID: Raspbian
This had to be one of the most frustrating things I have had to figure out in quite some time! As part of the process of reducing equipment I had to reconfigure my network layout. On my home/office setup, I have multiple networks so I can segregate my household, office, cameras, and wifi equipment in order to have better security. Usually this takes me an hour or so to swap around when I’ve changed stuff, but yesterday I spent over 5 hours working on it.
The problem I ran into was that on the network that I host external servers on (Net2), I could access the Internet, and I could do the same from my internal network (Net1), but I could not seem to punch a single hole through the fire wall between my work machine on Net1 and the servers I needed to work on. My typical habit is to open a port through the firewall, do the work I need to do, then close it up. While I could have walked over and plugged in to do the work I needed to, the fact that it wasn’t behaving as I expected left me wondering what else I was missing. Rather than run the risk of a security problem, I kept banging my head off the problem.
Setting a static IP address on a Rasberry Pi, as with all other Linux running machines, has long been as easy as editing the interfaces file. Apparently that’s changing, and with a lack of good documentation out there I had to read through hours of RFCs, and trial and error to make it happen. I found two or three different examples on the net on how to accomplish what I wanted, but they all seemed to have something wrong with them. Some used an equal sign between the properties and the setting, while others didn’t. Some used semi-colons to terminate the statements, while others did not. Most still tried to edit the /etc/network/interfaces file, which failed to actually change the ip address on a permanent basis. But my favorite of all were the guides that didn’t even try, they just said, “Change it in your firewall!”
The problem for me is I’m setting up some machines (Rasberry Pis) that I’m going to host some small sites on, that I want to be able to take with me when I travel. I set them up in such a way that they hold a static IP, then put an entry in my laptop /etc/hosts file that lets me access them simply by plugging them into the same switch. no router, no firewall, nothing else required. I can do what I need to without Internet access. Setting the static IP in the firewall wouldn’t be enough in this situation.
SO… I’m not claiming that the code below is the only, or even the best way to do it, but it’s how I did it, and it works perfectly at this point. I’m only writing this because I’m hoping it will save someone else the frustration that I went through.
Add the following to the /etc/dhcpcd.conf file,
static domain_name_servers=192.168.11.1 22.214.171.124 126.96.36.199
The interface should match the interface you’re trying to assign a static IP address to. And the key to my above problem was that I missed the /24 at the end of the ip address which is now seemingly required in order for it to pull the correct subnet mask. Leaving this /24 off causes a different subnet result, and there is apparently no documented option for setting subnet mask explicitly. If you find one, please post in the comments!
Rather than using the old gateway option, you use the routers option to point to your gateway.
DNS servers are now spelled out and should be space separated as demonstrated.
All entries require the equal sign
Finally no ; should be used at the end of the lines. In fact, in my experience adding them caused the line to be ignored.