Technology Encyclopedia Home >How to set a static IP on Raspbian?

How to set a static IP on Raspbian?

To set a static IP on Raspbian, you need to modify the network configuration files. Here’s how you can do it:

  1. Open the Terminal: You can find the Terminal in the Applications menu under "Utilities".

  2. Edit the Network Configuration File:

    • Type sudo nano /etc/dhcpcd.conf and press Enter.
    • This command opens the dhcpcd configuration file in a text editor.
  3. Add Static IP Configuration:

    • Scroll to the bottom of the file and add the following lines, replacing eth0 with your network interface (like wlan0 for Wi-Fi) and adjusting the IP address, netmask, gateway, and DNS servers as needed:
      interface eth0
      static ip_address=192.168.1.100/24
      static routers=192.168.1.1
      static domain_name_servers=8.8.8.8 8.8.4.4
      
    • Save and exit by pressing Ctrl+X, then Y, and Enter.
  4. Restart the Network Service:

    • Type sudo systemctl restart dhcpcd and press Enter to apply the changes.
  5. Verify the Configuration:

    • Use ip addr show eth0 or ifconfig eth0 to check if the static IP has been assigned correctly.

Example:
If you want to set a static IP of 192.168.1.100 on the wlan0 interface, your configuration would look like this:

interface wlan0
static ip_address=192.168.1.100/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8 8.8.4.4

For cloud-related services, if you need to manage your Raspberry Pi's network settings remotely or host services on it, consider using Tencent Cloud’s services like Tencent Cloud Server for hosting and managing your devices, or Tencent Cloud IoT Explorer for IoT device management.