techforay
Posts: 47
Joined: Thu Dec 27, 2012 1:28 am
Location: Puyallup Wa. USA

Static IP address

Sat Jan 18, 2020 8:56 pm

I am trying to give my Raspberry Pi 4 running Raspbian buster a static IP address. I am new to this and am trying to learn. I have been modifying the dhcpcd.conf file. I can get the ip to change but I wont connect to the internet after it is changed. I have tried to follow a couple of YouTube videos and may have messed up my dhcpcd.conf file although I am connected now through dhcp. I have two questions

1. Is there some place to get the default dhcpcd.conf file so I can get back to where is started

2. Can I get some instruction on setting up static iP addresses. I remote into it and lose the ability every time the IP address changes. Thank you in advance for your help.

I have copy and pasted the file below
#interface wlan0
#static ip_address=http://10.0.0.32/24
#satic router=10.0.0.1
#static domain_name_servers=127.0.0.1

# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit
# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# Most distributions have NTP support.
#option ntp_servers

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate SLAAC address using the Hardware Address of the interface
#slaac hwaddr
# OR generate Stable Private IPv6 Addresses based from the DUID
slaac private
# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# Most distributions have NTP support.
#option ntp_servers

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate SLAAC address using the Hardware Address of the interface
#slaac hwaddr
# OR generate Stable Private IPv6 Addresses based from the DUID
slaac private

# Example static IP configuration:
#interface eth0
#static ip_address=http://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=http://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
# Example static IP configuration:
#interface eth0
#static ip_address=http://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=http://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
#added the below for USB-C connection
denyinterfaces usb0

#interface eth0
#static ip_address=10.0.0.100

#interface wlan0
#static ip_address=10.0.0.99

#static routers=10.0.0.1

#static domain_name_servers=8.8.8.8 8.8.4.4

dustnbone
Posts: 329
Joined: Tue Nov 05, 2019 2:49 am

Re: Static IP address

Sat Jan 18, 2020 10:12 pm

Remember that for a line to be valid you need to uncomment it.

Lines beginning with # are considered comments and will be ignored by the daemon, so you must remove that # from lines you want to "use"

This convention applies to most configuration files in Linux.

Personally, I prefer to configure my router to give a static DHCP lease to systems that need the same IP all the time, and just allow DHCP to act as normal. You tell the router the MAC address of the Pi, and when it gets a DHCP request from that MAC address it assigns it the correct IP.

How this is done varies depending on your particular router, but it's usually in the configuration pages under "Static Lease" or "DHCP Reservation" or something similar.

techforay
Posts: 47
Joined: Thu Dec 27, 2012 1:28 am
Location: Puyallup Wa. USA

Re: Static IP address

Sat Jan 18, 2020 11:04 pm

Yes i know about the # commenting things out. Those are all the things i tried to get the static ip address to work. That is why i asked if i could find a clean file out there to get it back to the default.

epoch1970
Posts: 5472
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Static IP address

Sat Jan 18, 2020 11:23 pm

Static IP address: https://www.raspberrypi.org/documentati ... /README.md
To get back to the original config file, just reinstall the package: “apt-get install --reinstall dhcpcd5”
(or look for instructions on how to download a debian package without installing it, and how to unpack it.)
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

LTolledo
Posts: 3820
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Static IP address

Sun Jan 19, 2020 12:23 am

I also set my router to reserve IP address for my devices (PCs, smartphone, SBCs like the RPi, etc). This is only applicable if I have admin rights to the routers.

so even if the device changes location to a different router.... the device can still get another IP address on that other router (may be static if reserved there, otherwise its auto)
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

GlowInTheDark
Posts: 880
Joined: Sat Nov 09, 2019 12:14 pm

Re: Static IP address

Sun Jan 19, 2020 3:31 am

I know that the "supported/approved answer" to this sort of thing is to "do it in the router" (as the last few responses attest), but the problem with that is that the reason people want to use static IP in the first place is because they either can't use or don't trust the DHCP server. I.e., you use static IP when the normal stuff isn't working. If the normal stuff is working, then you'd just do normal DHCP.

Yes, yes, I know some smart people here will come up with exceptions, reasons why they need static IP and why they do it the way they do it, but (short version) those reasons don't matter. They don't apply to the sorts of people and situations that cause these sorts of threads to be started.
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

dustnbone
Posts: 329
Joined: Tue Nov 05, 2019 2:49 am

Re: Static IP address

Sun Jan 19, 2020 3:54 am

I guess in this case I assumed (not necessarily correctly) that since OP was accessing the Pi from outside the LAN, via port forwarding, they had access to the router configuration. They want a consistent IP on the Pi so that port is forwarded to the correct device on the LAN.

The reason that doing it from the routers DHCP server is preferred IMHO, is to avoid IP conflict in the case of the routers DHCP assigning the IP configured on the Pi to another device on the LAN.

So, if you ARE going to assign a static IP to a device on a network that has an active DHCP server running, you need access to that DHCP servers configuration in order to ensure your static IP is outside the range of automatically assigned addresses.

ejolson
Posts: 5637
Joined: Tue Mar 18, 2014 11:47 am

Re: Static IP address

Sun Jan 19, 2020 4:42 am

dustnbone wrote:
Sun Jan 19, 2020 3:54 am
I guess in this case I assumed (not necessarily correctly) that since OP was accessing the Pi from outside the LAN, via port forwarding, they had access to the router configuration. They want a consistent IP on the Pi so that port is forwarded to the correct device on the LAN.

The reason that doing it from the routers DHCP server is preferred IMHO, is to avoid IP conflict in the case of the routers DHCP assigning the IP configured on the Pi to another device on the LAN.

So, if you ARE going to assign a static IP to a device on a network that has an active DHCP server running, you need access to that DHCP servers configuration in order to ensure your static IP is outside the range of automatically assigned addresses.
Configuring the DHCP server in the router to assign the same IP number to the Pi based on its MAC address is a good and convenient solution. My home router is too simple to allow this, but it did allow me to configure the range that it will issue leases for. Thus, I've set the DHCP server to assign numbers in the range from xxxxxxx.128 to xxxxxxx.254. This leaves xxxxxxx.2 through xxxxxxx.127 for any static numbers I want to assign and there is no chance of collision that way.

User avatar
rpdom
Posts: 17452
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Static IP address

Sun Jan 19, 2020 8:42 am

GlowInTheDark wrote:
Sun Jan 19, 2020 3:31 am
I know that the "supported/approved answer" to this sort of thing is to "do it in the router" (as the last few responses attest), but the problem with that is that the reason people want to use static IP in the first place is because they either can't use or don't trust the DHCP server. I.e., you use static IP when the normal stuff isn't working. If the normal stuff is working, then you'd just do normal DHCP.

Yes, yes, I know some smart people here will come up with exceptions, reasons why they need static IP and why they do it the way they do it, but (short version) those reasons don't matter. They don't apply to the sorts of people and situations that cause these sorts of threads to be started.
This is true. I do use reserved addresses via DHCP (I disabled dhcp on my router - it is handles by a Pi running dnsmasq instead, which is more flexible), but I do have a couple of Pis where I have fixed the IP address in dhcpcd.conf because they need to have those IP addresses even if they can't contact the DHCP server for any reason.
Unreadable squiggle

epoch1970
Posts: 5472
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Static IP address

Sun Jan 19, 2020 10:47 am

Well the network doesn’t really care for your situation or your reasons. Either you follow the established protocol and you can communicate, or you don’t, and have trouble. Dura lex sed lex.

Without the help of DHCP, establishing a guaranteed working manual static IP address for a host requires the talent of a mind reader. Unless you are the admin of that network, or you are willing and able to do some detective work.

Lease reservation via DHCP is the best practice and usually ISP routers make that pretty easy.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

User avatar
rpdom
Posts: 17452
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Static IP address

Sun Jan 19, 2020 12:01 pm

epoch1970 wrote:
Sun Jan 19, 2020 10:47 am
Without the help of DHCP, establishing a guaranteed working manual static IP address for a host requires the talent of a mind reader. Unless you are the admin of that network,
Pretty much everyone with a home router is the admin of their network, whether they realise/understand it or not.
Unreadable squiggle

GlowInTheDark
Posts: 880
Joined: Sat Nov 09, 2019 12:14 pm

Re: Static IP address

Sun Jan 19, 2020 12:07 pm

Just so you know, if the last few responses are in reference to my post and if they are supposed to convince me that I was wrong in some way, I just want you to know that you're talking to the hand.

If this is not the case, then, of course, please disregard this post...
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

User avatar
rpdom
Posts: 17452
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Static IP address

Sun Jan 19, 2020 12:18 pm

GlowInTheDark wrote:
Sun Jan 19, 2020 12:07 pm
Just so you know, if the last few responses are in reference to my post and if they are supposed to convince me that I was wrong in some way, I just want you to know that you're talking to the hand.

If this is not the case, then, of course, please disregard this post...
Um, I mostly agreed with you. But if you want to ignore that, fine. I shall put you on my ignore list.
Unreadable squiggle

Return to “Beginners”