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:
-
Open the Network Manager by clicking on the network icon in the top right corner of the screen and selecting "Edit Connections."
-
Select the network connection you want to set a fixed IP address for and click "Edit."
-
In the IPv4 Settings tab, change the Method dropdown from "Automatic (DHCP)" to "Manual."
-
Click "Add" to add a new IP address, subnet mask, and default gateway.
-
Enter the IP address, subnet mask, and default gateway that you want to use for your connection.
-
Optionally, you can also add DNS servers under the DNS tab.
-
Click "Save" to save the changes.
-
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:
-
Open the terminal on your Debian system.
-
Type
nmtui
and press Enter to open the Network Manager Text User Interface. -
Navigate to the connection you want to modify using the arrow keys.
-
Press Enter to select the connection.
-
Navigate to the "Edit a connection" option and press Enter.
-
Navigate to the "IPv4 CONFIGURATION" option and press Enter.
-
Change the "Method" from "Automatic" to "Manual" using the arrow keys.
-
Navigate to the "Addresses" option and press Enter.
-
Use the arrow keys to select "Add" and press Enter to add a new IP address.
-
Enter the IP address, subnet mask, and default gateway that you want to use for your connection.
-
Optionally, you can also add DNS servers under the "DNS servers" option.
-
Press Tab to move to the "OK" button and press Enter to save the changes.
-
Press Tab to move to the "Back" button and press Enter to exit the editing screen.
-
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:
-
Open the terminal on your Debian system.
-
Use the following command to display a list of available network connections:
nmcli con show
-
Find the name of the connection you want to set a fixed IP address for and make note of it.
-
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
-
After entering the command, press Enter to execute it.
-
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"
- 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.
本文作者:云子墨
本文链接:https://www.cnblogs.com/yunzimo/p/17228030.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」