In the process of using the Raspberry Pi, DHCP will often automatically assign the Raspberry Pi’s IP, so the IP address of the Raspberry Pi is not fixed, so you need to check the Raspberry Pi’s IP address every time you log in to the Raspberry Pi remotely. IP address is very troublesome. Therefore, after we manually set a static IP address for the Raspberry Pi, the IP address of the Raspberry Pi is fixed.
Type in the Raspberry Pi terminal:
sudo nano /etc/dhcpcd.conf
After entering the file, find the code as shown below at the bottom of the file:
If you need to fix the IP of the Raspberry Pi when using the network cable, you can remove the comment symbol "#" and change the static IP to the Raspberry Pi IP when using the network cable. The router/network management IP address should also be modified:
If you need to fix the IP of the Raspberry Pi when using wireless, you need to eth0
change it wlan0
, remove the comment symbol #
, and change the static IP to the Raspberry Pi IP when connected to wireless:
After modification, press ctrl+x
, y
to enter
save and exit the file
Restart the Raspberry Pi:
sudo reboot
Use the command again in the terminal to view the IP address:
ifconfig
Test whether the Raspberry Pi can connect to the Internet:
ping baidu.com
ipconfig
Check the router ip address under Windows :
-
In the start menu search box,
cmd
after entering OK, open the command dialog -
Enter the
ipconfig
instruction, click theEnter
button to confirm -
In the pop-up message, find the default gateway, which corresponds to the IP address
Note: The static IP manually set cannot be the same as the IP automatically assigned by the router DHCP, otherwise the Raspberry Pi may not be able to connect to the Internet normally.