Debian 设置静态IP (Answer from ChatGPT)

My Debian System uses the network manager, so how do I set up a fixed IP address

To set up a fixed IP address on Debian using Network Manager, you can follow these steps:

  1. Open the Network Manager by clicking on the network icon in the top right corner of the screen and selecting "Edit Connections."

  2. Select the network connection you want to set a fixed IP address for and click "Edit."

  3. In the IPv4 Settings tab, change the Method dropdown from "Automatic (DHCP)" to "Manual."

  4. Click "Add" to add a new IP address, subnet mask, and default gateway.

  5. Enter the IP address, subnet mask, and default gateway that you want to use for your connection.

  6. Optionally, you can also add DNS servers under the DNS tab.

  7. Click "Save" to save the changes.

  8. Close the Network Manager and restart the network service with the following command: sudo systemctl restart networking

After completing these steps, your Debian system should now have a fixed IP address assigned to the selected network connection.

How do I modify the above methods through nmtui

You can modify the network settings of a connection using the nmtui tool by following these steps:

  1. Open the terminal on your Debian system.

  2. Type nmtui and press Enter to open the Network Manager Text User Interface.

  3. Navigate to the connection you want to modify using the arrow keys.

  4. Press Enter to select the connection.

  5. Navigate to the "Edit a connection" option and press Enter.

  6. Navigate to the "IPv4 CONFIGURATION" option and press Enter.

  7. Change the "Method" from "Automatic" to "Manual" using the arrow keys.

  8. Navigate to the "Addresses" option and press Enter.

  9. Use the arrow keys to select "Add" and press Enter to add a new IP address.

  10. Enter the IP address, subnet mask, and default gateway that you want to use for your connection.

  11. Optionally, you can also add DNS servers under the "DNS servers" option.

  12. Press Tab to move to the "OK" button and press Enter to save the changes.

  13. Press Tab to move to the "Back" button and press Enter to exit the editing screen.

  14. Press Tab to move to the "Quit" button and press Enter to exit the nmtui tool.

After completing these steps, your Debian system should now have a fixed IP address assigned to the selected network connection.

How to set a fixed IP address using the nmcli command

To set a fixed IP address using the nmcli command in Debian, you can follow these steps:

  1. Open the terminal on your Debian system.

  2. Use the following command to display a list of available network connections: nmcli con show

  3. Find the name of the connection you want to set a fixed IP address for and make note of it.

  4. Use the following command to set a fixed IP address for the selected connection:

sudo nmcli con mod <connection_name> ipv4.method manual ipv4.addresses <ip_address>/<subnet_mask> ipv4.gateway <default_gateway> ipv4.dns <dns_server_address>

Make sure to replace <connection_name>, <ip_address>, <subnet_mask>, <default_gateway>, and <dns_server_address> with the actual values for your network configuration.

For example, if you want to set a fixed IP address of "192.168.1.100" with a subnet mask of "255.255.255.0" and a default gateway of "192.168.1.1" and a DNS server of "8.8.8.8" for a connection named "eth0", the command would be:

sudo nmcli con mod eth0 ipv4.method manual ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns 8.8.8.8
  1. After entering the command, press Enter to execute it.

  2. Use the following command to verify that the changes have been applied:

sudo nmcli con show <connection_name> | grep -w "IP4.ADDRESS\|IP4.GATEWAY\|IP4.DNS"

Make sure to replace <connection_name> with the name of the connection you just modified.

For example, if you modified a connection named "eth0", the command would be:

sudo nmcli con show eth0 | grep -w "IP4.ADDRESS\|IP4.GATEWAY\|IP4.DNS"
  1. After verifying the changes, you can exit the terminal.

After completing these steps, your Debian system should now have a fixed IP address assigned to the selected network connection.

Will this method still take effect after restarting

Yes, the changes made using the nmcli command will persist after restarting your Debian system. The modified connection will have the fixed IP address configuration even after a reboot or network service restart.

posted @ 2023-03-17 20:09  云子墨  阅读(72)  评论(0编辑  收藏  举报