[출처] https://www.abelectronics.co.uk/kb/article/31/set-a-static-ip-address-on-raspberry-pi-os-bookworm

 

This tutorial details how to set up a static network IP address on the Ethernet or WiFi connection on the Raspberry Pi OS Bookworm image, released October 2023, from https://www.raspberrypi.org/software/operating-systems/.

With the release of Raspberry Pi OS Bookworm, networking on the Raspberry Pi was changed to use NetworkManager as the standard controller for networking, replacing the previous dhcpcd system. NetworkManager includes a command line tool called “nmcli,” which can control NetworkManager and report on the network status.

This tutorial will use “nmcli” to configure the network to use a static IP address.

We will give the Raspberry Pi a static IP address of 10.0.0.220. The gateway address will be set at 10.0.0.1, and the DNS server will also be set to 10.0.0.1

 

Step 1:

The first step is to find the name of the network interface you want to set as static. Run the following command in a terminal to display a list of available network interfaces.

sudo nmcli -p connection show

You should see a listing like the one below.

======================================
  NetworkManager connection profiles
======================================
NAME                UUID                                  TYPE      DEVICE
----------------------------------------------------------------------------
Wired connection 1  bd220d18-7d6a-36a5-9820-4f67de2c01fc  ethernet  eth0
mywifi              2359440b-8991-4c86-a905-b011dced4587  wifi      wlan0
lo                  c29ba7c5-98ff-4fa0-8d8e-06b30b8ec384  loopback  lo

The default name for the wired ethernet connection for English locales is “Wired connection 1”. This name may be different if you use another language; for example, the German name will be “Kabelgebundene Verbindung 1”. To find the correct connection name, look for the row with a Type of “ethernet”.

The WiFi connection will typically have the name of your WiFis SSID. If your Raspberry Pi uses different names for the network connections or you would like to change your WiFi IP address, replace “Wired connection 1” with the correct name in the following commands.

 

Step 2:

Now we know the name of the network connection we want to update, we can send three commands to set the new IP address, Gateway and DNS server.

sudo nmcli c mod "Wired connection 1" ipv4.addresses 10.0.0.220/24 ipv4.method manual

sudo nmcli con mod "Wired connection 1" ipv4.gateway 10.0.0.1

sudo nmcli con mod "Wired connection 1" ipv4.dns 10.0.0.1

한글로 세팅하는 경우 “Wired connection 1″이 “유선연결1 ” 과 같이 한글로 되어 있는 경우가 있다. 이때는 한글인식이 잘 안되므로 그냥 UUID를 따옴표 없이 적어줘도 무방하다.

sudo nmcli c mod “Wired connection 1” ipv4.addresses 10.0.0.220/24 ipv4.method manual

= sudo nmcli c mod  bd220d18-7d6a-36a5-9820-4f67de2c01fc   ipv4.addresses 10.0.0.220/24 ipv4.method manual

 

If you want to use multiple DNS servers, you can add them separated by commas; for example, to use Google’s DNS servers, use the following.

sudo nmcli con mod "Wired connection 1" ipv4.dns "8.8.8.8,8.8.4.4"

 

The same method can be used for adding multiple IP addresses to the same network connection; for example, the following command would assign IP addresses 10.0.0.220, 10.0.0.221 and 10.0.0.222.

sudo nmcli c mod "Wired connection 1" ipv4.addresses "10.0.0.220/24, 10.0.0.221/24, 10.0.0.222/24" ipv4.method manual

 

Step 3:

When you have finished updating the network settings on your Raspberry Pi, you can restart the network connection with the following command.

sudo nmcli c down "Wired connection 1" && sudo nmcli c up "Wired connection 1"

 

Note: If you are using SSH to connect to your Raspberry Pi, running the above command will cause the SSH session to end if the IP address changes.

You can find all of the configuration settings for a network connection with the following command:

nmcli -p connection show "Wired connection 1"

To change the network connection from static to automatic, run the following commands:

sudo nmcli con modify "Wired connection 1" ipv4.method auto
sudo nmcli c down "Wired connection 1" && sudo nmcli c up "Wired connection 1"

By yaplab

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다