I've almost been doing that. The only thing I didn't do was the /24 at the end of the IP. Here's the steps I've been following:
The first step is to find out your default gateway IP. This is the local IP address of your network router. The computers on your network use it to communicate with the router and access the internet. If you already know what it is, just skip this step. If not, do continue…
Power up and log into your Raspberry Pi via WiFi or ethernet, then enter route -ne at the command prompt to see your network routing information:
Under the “Gateway” column, you can see your default gateway IP. The “Iface” column lists the names for each connection – ethernet (eth0) and WiFi (wlan0). Write down your default gateway IP, we’ll need it in a minute.
Now we need to find out the IP addresses of your domain name servers. Your Pi sends the domain names you enter into your browser (i.e.
www.google.com) to domain name servers, which convert the domain names to IP addresses (i.e. 8.8.8.8). Your Pi then uses the IP address to access the website’s server.
Enter cat /etc/resolv.conf at the command prompt to find the list of domain name servers:
Copy these IP addresses to a text editor on your PC or write them down for later.
Now we’re ready to configure the network settings. By default the Pi is configured with a dynamic IP address. To assign it a static IP address, you need to add your static IP, default gateway IP, and domain name servers to the dhcpcd.conf file.
At the command prompt, enter sudo nano /etc/dhcpcd.conf to edit the dhcpcd.conf file:
Now, without changing anything else in the file, add this code at the bottom of the dhcpcd.conf file, replacing the IP addresses with your own IP addresses found above:
interface eth0
static ip_address=192.168.1.100
static routers=192.168.1.254
static domain_name_servers=192.168.1.254 2600:1700:74a0:98c0::1
interface wlan0
static ip_address=192.168.1.99
static routers=192.168.1.254
static domain_name_servers=192.168.1.254 2600:1700:74a0:98c0::1
• static ip_address: This is the static IP address you’ll use to SSH or remotely connect to your Pi. Take your default gateway IP (found in the steps above), and change the last number to any other number between 0 and 255.
• static routers: This is your default gateway IP address.
• static domain_name_servers: These are the IP’s we found in the resolv.conf file above. Separate each IP with a single space.
For example, my default gateway IP address is 10.0.0.1. To get the static ip_address for my ethernet connection (eth0), I replaced the 1 with 100 to get 10.0.0.100. To get the static ip_address for my WiFi connection (wlan0), I replaced the 1 with 99 to get 10.0.0.99. I’ll use these IPs to log in to my Pi from now on.
Once you’ve replaced the IP addresses in the example code with your own IP addresses, press Ctrl-O and press enter then press Ctrl-X to exit the dhcpcd.conf file. Now enter sudo reboot to reboot the Pi. Log in with your new static ethernet IP or static WiFi IP.
When the rpi reboots, a string of numbers scroll down the monitor for some time. After the numbers scrolled for over 10 minutes, I got impatient and unplugged the power from the pi, then plugged it back in and it would finally reboot so i could continue. That may be why internet was sporadic on the pi. I just don't know if the scrolling numbers were updating something or if the pi OS got caught in a loop.