I set a static IP address for my pi. ( 192.168.1.103) by adding these lines to the top of the /etc/dhcpcd.conf file:
interface eth0
static ip_address=192.168.1.103/24
After reboot this works fine and I can access the pi through the new IP address, BUT now I cannot connect to the internet anymore.
I tried also adding the lines:
static routers=192.168.1.254
static domain_name_servers=8.8.8.8
which is what the link I got this information suggested but it made no difference.
I change one line to :
static routers=192.168.1.1
And that did not make any difference either.
This aught to be simple if you know what you are doing - and I don’t in this particular area.
Can someone help me to find out what I need to keep the static IP address and also be able to have internet access on my network?
I have added the lines to the top of the /etc/dhcpcd.conf file to be:
interface eth0
static ip_address=192.168.1.103/24
static routers = 192.168.1.1
static domain_name_servers=192.168.1.1
When I try to open a browser and put google in the URL I get:
This site can’t be reached http://www.google.com/ is unreachable.
ERR_ADDRESS_UNREACHABLE
Changing /etc/dhcpcd.conf file to:
interface eth0
static ip_address=192.168.1.103/24
static routers = 192.168.1.1
static domain_name_servers=8.8.8.8
I get:
No Internet Try: checking the network cables, modem and router, Reconfiguring your WiFi DNS_PROBE_FINISHED_NO_INTERNET
Changing /etc/dhcpcd.conf file to:
interface eth0
static ip_address=192.168.1.103/24
static routers = 192.168.1.1
static domain_name_servers=192.168.1.1
I have no problems, but I do not have a static IP anymore!
What is wrong? It seems that this simple thing is not so simple!
I have already tried your second link and done precisely what it instructs and while it changes the Pi to a static IP address successfully, it at the same time stops the internet access from working.
Hmm, it sounds like it might be an issue using the DNS, those settings can be found in your router and will change from model to model. Coincidentally Dougie covers it again here: No internet Connection - Raspberry Pi Forums
Let us know how you go with the other steps!
Liam.
Top of the /etc/dhcpcd.conf file is: interface eth0 static ip_address=192.168.1.103/24 static routers = 192.168.1.1 static domain_name_servers=192.168.1.1
Ping results:
ping 192.168.1.103 works
ping 192.168.1.1 works
ping 8.8.8.8 connect: Network is unreachable
ping www.google.com connect: Network is unreachable
cannot connect to internet
run command:
sudo ip route add default via 192.168.1.1
Ping results:
ping 192.168.1.103 works
ping 192.168.1.1 works
ping 8.8.8.8 works
ping www.google.com works
now CAN connect to internet
reboot
cannot access internet.
So how do I make the effect of this command permanent?: sudo ip route add default via 192.168.1.1
I found static IP addresses work better when assigned by the Router.
I find the MAC address of the Pi and then change the router configuration to assign an IP address to that MAC address.
The command sudo ip route add default via 192.168.1.1 would need to be added as one of the last commands upon boot up.
I use /etc/rc.local to add these type of commands. The & at the end of the line allows rc.local to end.
This might or might not work, I have not tested it.
But running my projects from /etc/rc.local certainly does work.
Regards
Jim
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
sudo ip route add default via 192.168.1.1 &
exit 0
I do not understand what this command actually does: ip route add default via 192.168.1.1
I would like to know,
further I would like to know why this cannot be set up in a configuration file so that this command does not need to be run?
The ip command adds a default route gateway to the ip routing table.
The following is from a Raspberry Pi I have setup as an environment monitor.
My Router DHCP server assigns the MAC address of the Pi as 192.168.1.23 IP address and specifies the default gateway as 192.168.1.1. The Raspberry Pi then configures itself for these addresses. This happens automatically.
pi@pizero008:~ $ ip route show
default via 192.168.1.1 dev wlan0 proto dhcp src 192.168.1.23 metric 302
192.168.1.0/24 dev wlan0 proto dhcp scope link src 192.168.1.23 metric 302
As you are setting this up manually the routing table would not have default via 192.168.1.1 when the Pi boots up. The command ip route show should give a list of the routing table contents (ip route list also works). This might help you figure out what is going on.
In my dhcpcd.conf file the static assignment lines are commented out near the bottom of the file. Suggest placing your lines at the bottom not at the top.
Also there is are spaces around the equals in the line static routers = 192.168.1.1. Past experience has shown Linux can sometimes be fussy with spaces. Suggest removing the spaces. Below is the lines of the dhcpcd.conf on the Pi related to setting static addresses. The # means the line is treated like a comment and ignored, remove to enable the line.
# Example static IP configuration:
#interface eth0
#static ip_address=192.168.0.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1
# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1
# fallback to static profile on eth0
#interface eth0
#fallback static_eth0
Hi Clem
I think Jame’s comment from 3 days ago should be revisited. You need to get your router to assign a static IP address on your local network to your RPi. Log into your router’s admin page and the right part for these assignments. -Its appearance varies with the brand of router. Good luck!
I like the idea of requesting the router to give the desired IP address.
I tried this as per the link by editing the '/etc/dhcpcd.conf ’ file by adding the lines:
’
interface eth0
request 192.168.1.104
’
I also tried this with no different result:
’
interface eth0
request 192.168.1.104/24
’
To my disapointment this did not work it just allocated some other IP address: ‘192.168.1.4’
I like the idea of doing it this way - how can I get this to work?
You have to ask the router unfortunately - but most applications won’t need the full 255 (or even close to it) so it’s become a bit of a defacto standard practice to only automatically IP addresses above 100. This gives you almost 100 IP addresses to use for static allocations - without needing to learn much of anything about networking.
This command does not give any error, and it adds another Ethernet address to the pi.
command hostname -I prior returns: 192.168.1.4 192.168.1.15
.4 is the non static allocated ip for eth0, …15 is the wifi ip.
after command