keiichi
Posts: 54
Joined: Mon Jul 27, 2015 8:33 pm

Set static ip on raspberry pi 2B

Wed Jun 16, 2021 9:09 am

Salve,
Ho un raspberry pi 2 B al quale, da qualche tempo, sono saltati sia l'impostazione dell'ip statico sia quella del DNS.
Sono andato a vedere diverse guide tra le quali

Hi everyone,
i've a raspberry pi 2B. I want reset a static ip because the previously set is broken.
I looked some guides like the following:
https://www.ionos.it/digitalguide/serve ... -ip-fisso/
viewtopic.php?t=275161

Now there are some my system's outputs:

Code: Select all

$ ifconfig
enxb827eb9eb66a: flags=-28605<UP,BROADCAST,RUNNING,MULTICAST,DYNAMIC>  mtu 1500
        inet 192.168.1.21  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::ba27:ebff:fe9e:b66a  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:9e:b6:6a  txqueuelen 1000  (Ethernet)
        RX packets 9494  bytes 6268021 (5.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8421  bytes 2442858 (2.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 41  bytes 3779 (3.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 41  bytes 3779 (3.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Code: Select all

$ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
#auto eth0
#iface eth0 inet static
# address 192.168.1.138/24
# netmask 255.255.255.0
I tried to comment the row /etc/network/interfaces.d and uncomment the following rows without results.

Code: Select all

$ cat dhclient.conf 
# Configuration file for /sbin/dhclient.
#
# This is a sample configuration file for dhclient. See dhclient.conf's
#	man page for more information about the syntax of this file
#	and a more comprehensive list of the parameters understood by
#	dhclient.
#
# Normally, if the DHCP server provides reasonable information and does
#	not leave anything out (like the domain name, for example), then
#	few changes must be made to this file, if any.
#

option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
	domain-name, domain-name-servers, domain-search, host-name,
	dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
	netbios-name-servers, netbios-scope, interface-mtu,
	rfc3442-classless-static-routes, ntp-servers;

#send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
#send dhcp-lease-time 3600;
#supersede domain-name "fugue.com home.vix.com";
prepend domain-name-servers 208.67.222.222, 208.67.220.220, 8.8.8.8, 8.8.4.4;
#prepend domain-name-servers 127.0.0.1;
#require subnet-mask, domain-name-servers;
#timeout 60;
#retry 60;
#reboot 10;
#select-timeout 5;
#initial-interval 2;
#script "/sbin/dhclient-script";
#media "-link0 -link1 -link2", "link0 link1";
#reject 192.33.137.209;

#alias {
#  interface "eth0";
#  fixed-address 192.5.5.213;
#  option subnet-mask 255.255.255.255;
#}

#lease {
#  interface "eth0";
#  fixed-address 192.33.137.200;
#  medium "link0 link1";
#  option host-name "andare.swiftmedia.com";
#  option subnet-mask 255.255.255.0;
#  option broadcast-address 192.33.137.255;
#  option routers 192.33.137.250;
#  option domain-name-servers 127.0.0.1;
#  renew 2 2000/1/12 00:00:01;
#  rebind 2 2000/1/12 00:00:01;
#  expire 2 2000/1/12 00:00:01;
#}
How i can solve?
Thanks everybody

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

Re: Set static ip on raspberry pi 2B

Wed Jun 16, 2021 9:18 am

If you're using Raspios:
https://www.raspberrypi.org/documentati ... ion/tcpip/

Remove what you added in /etc/network/interfaces. It breaks networking.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

drgeoff
Posts: 12057
Joined: Wed Jan 25, 2012 6:39 pm

Re: Set static ip on raspberry pi 2B

Wed Jun 16, 2021 9:56 pm

See the 3rd commented line of /etc/network/interfaces.
Quis custodiet ipsos custodes?

keiichi
Posts: 54
Joined: Mon Jul 27, 2015 8:33 pm

Re: Set static ip on raspberry pi 2B

Fri Jun 18, 2021 9:38 am

drgeoff wrote:
Wed Jun 16, 2021 9:56 pm
See the 3rd commented line of /etc/network/interfaces.
The file /etc/dhcpcd.conf was already written as the follow:

Code: Select all

$ cat /etc/dhcpcd.conf 
interface eth0
static ip_address=192.168.1.138/24
static routers=192.168.1.1
static domain_name_servers=208.67.222.222 208.67.220.220 1.1.1.1 8.8.8.8 8.8.4.4
epoch1970 wrote:
Wed Jun 16, 2021 9:18 am
If you're using Raspios:
https://www.raspberrypi.org/documentati ... ion/tcpip/

Remove what you added in /etc/network/interfaces. It breaks networking.
Now /etc/network/interfaces is all commentated

There are not results

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

Re: Set static ip on raspberry pi 2B

Fri Jun 18, 2021 1:23 pm

The interface is called eth0 or enxb827eb9eb66a?

What does "no results" mean? Post outputs of commands that show what's wrong.
"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
B.Goode
Posts: 12242
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Set static ip on raspberry pi 2B

Fri Jun 18, 2021 1:42 pm

keiichi wrote:
Fri Jun 18, 2021 9:38 am


Now /etc/network/interfaces is all commentated

There are not results

I believe that in the version of that file installed by default with the RasPiOS Buster Operating System there is a line that is still active ( = NOT commented out )

(This might or might not be significant in exploring your issue.)

keiichi
Posts: 54
Joined: Mon Jul 27, 2015 8:33 pm

Re: Set static ip on raspberry pi 2B

Fri Jun 18, 2021 3:34 pm

epoch1970 wrote:
Fri Jun 18, 2021 1:23 pm
The interface is called eth0 or enxb827eb9eb66a?

What does "no results" mean? Post outputs of commands that show what's wrong.
I changed the interface name in /etc/dhcpcd.conf from eth0 in enxb827eb9eb66a but the raspberry does not use the ip that i want

Code: Select all

$ cat /etc/dhcpcd.conf 
interface enxb827eb9eb66a
static ip_address=192.168.1.138/24
static routers=192.168.1.1
static domain_name_servers=208.67.222.222 208.67.220.220 1.1.1.1 8.8.8.8 8.8.4.4
$ ifconfig
enxb827eb9eb66a: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.21  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::ba27:ebff:fe9e:b66a  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:9e:b6:6a  txqueuelen 1000  (Ethernet)
        RX packets 3735  bytes 1370364 (1.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4061  bytes 1337494 (1.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 29  bytes 2779 (2.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 29  bytes 2779 (2.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
B.Goode wrote:
Fri Jun 18, 2021 1:42 pm
I believe that in the version of that file installed by default with the RasPiOS Buster Operating System there is a line that is still active ( = NOT commented out )

(This might or might not be significant in exploring your issue.)

Code: Select all

$ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
#source-directory /etc/network/interfaces.d
#auto eth0
#iface eth0 inet static
# address 192.168.1.138/24
# netmask 255.255.255.0
The directory /etc/network/interfaces.d is empty

Code: Select all

/etc/network/interfaces.d $ ls
$ 

pfletch101
Posts: 661
Joined: Sat Feb 24, 2018 4:09 am
Location: Buffalo, NY, USA

Re: Set static ip on raspberry pi 2B

Mon Jun 21, 2021 2:19 pm

In general, you should let your router or DHCP server (if the latter is separate from your router, which is not usual in SOHO setups) handle IP address assignment. Setting fixed addresses on peripheral devices frequently leads to confusion, or worse, particularly when subsequent changes are made to the network and/or a device is moved to a different network. If you want a peripheral device to have a constant IP address, which is a perfectly common and reasonable thing to want, the best way (IMHO) of achieving this is to have the DHCP server assign 'fixed' IP addresses to any peripheral devices which need them, based on their MAC addresses. Most routers have configuration settings that allow this.

Return to “Networking and servers”