当前位置:网站首页>Ubuntu Topic 5: Setting a Static IP Address
Ubuntu Topic 5: Setting a Static IP Address
2022-07-31 14:56:00 【python-code dr】
ubuntu20.04 Dynamic is used by defaultIP设置,But sometimes we need to set static for itIP.This article will guide you to fully understandubuntu20.04的IP设置方法.
networking 和 network-manager
Figure it out before you startnetworking
服务和network-manager
服务的区别.
networking
是控制系统网络设置的,如果你修改了相关的网络配置需要重启此服务.
而network-manager
是管理networking
服务的一个图形化管理工具的后台服务程序.
为了继续下面的操作,需要大家安装一下net-tools
,以及ifupdown
,并重启一下系统.
sudo apt install -y ifupdown net-tools
init 6
联通性测试.
一切正常.
至此大家对network-manager
Is there any impression?
继续.
通过修改/etc/network/interfaces 配置静态IP
Next, let's modify it``/etc/network/interfaces来配置ubuntu20.04`的静态IP地址.
Let's take a look at the previous oneIP地址.
vim /etc/network/interfaces
在文件interfaces
中添加如下内容.
auto lo
iface lo inet loopback
auto ens33
iface ens33 inet static
address 192.168.2.117
netmask 255.255.255.0
gateway 192.168.2.1
此处的address修改成了’192.168.2.117’
I'll reboot firstnetwork-manager
Check the system againIP地址,You will find that nothing has changed.
Let's reboot againnetworking
服务吧.
systemctl restart networking
Modified is shownIP了.
如果通过systemctl restart networking
The modified version is also not displayed properlyIP的话,可以重启一下系统. I don't know if it is hereubuntu的bug
再用ip a
查看一下
联通性测试
ping baidu.com
网络不通,The above information prompt is because there is no设置DNS
.
修改/etc/systemd/resolved.conf
而不是修改/etc/resolved.conf
,如果修改/etc/resolved.conf
,重启系统DNS会失效.
su
echo "DNS=192.168.2.1 8.8.8.8" >> /etc/systemd/resolved.conf
systemctl restart systemd-resolved
多个DNS之间用空格分开.
Restart the system and test again.
Modified so far/etc/network/interfaces
file to configure staticallyIP的工作完成.
But the static modified by the above methodIPYou'll find one on the network icon in the upper right corner of the desktop"?".
对于有强迫症的人来说,will feel very uncomfortable.
解决方案一:Compromise solution–眼不见为净
systemctl stop network-manager
systemctl disable networ-manager
解决方案二:通过图形化界面`network-manager`设置静态IP
继续上面的步骤:先开启network-manager
(系统默认是开启的,The invisible solution in the previous step turned it off.)
sudo systemctl enable network-manager
sudo systemctl start network-manager
Empty our frontinterfaces
文件中的配置内容.
cat /dev/null > /etc/network/interfaces
重启系统.
init 6
The network icon in the upper right corner of the desktop reappeared,点击它.
通过ip a
命令检验.
解决方案三(推荐):使用`netplan` 命令设置静态IP
ubuntu20.04
推荐使用netplan命令设置静态IP地址.
netplan
使用yaml
Format configuration file to configure network addresses.
vim /etc/netplan/01-network-manager-all.yaml
在01-network-manager-all.yaml
文件中rendererAdd the following after that line.
ethernets:
ens33:
addresses: [192.168.2.116/24]
gateway4: 192.168.2.1
nameservers:
addresses: [192.168.2.1,8.8.8.8]
The finished file looks like this.
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
ethernets:
ens33:
addresses: [192.168.2.116/24]
gateway4: 192.168.2.1
nameservers:
addresses: [192.168.2.1,8.8.8.8]
注意yaml
Files are indented to control the relationship between the upper and lower levels,Your indentation can be one space or oneN个空格,But be consistent throughout the configuration file,And be careful to add a space after the colon.
让配置文件生效.
netplan apply
联通性测试.
OK
You can modify the configuration fileIP地址,通过netplan apply
命令,The address can take effect immediately.
Set up several commands commonly used in the network
# 关闭网卡 ifdown <网卡名称>
sudo ifdown ens33
ifdown: unknown interface ens33
报错的解决方法,使用命令
sudo ip link set ens33 down
# 或者使用命令
sudo ifconfig ens33 down
#开启网卡 ifup <网卡名称>
sudo ifup ens33
ubuntu20.04
中ifup: unknown interface ens33
报错的解决方法,使用命令
sudo ip link set ens33 up
# 或者使用命令
sudo ifconfig ens33 up
An error occurred: 'NetplanApply' object has no attribute 'state'
报错的解决方法.使用命令
netplan try --state /etc/netplan
边栏推荐
- How to clean up the lodash.memoize cache in the element-plus virtual table virtual-list component?
- Motion capture system for end-positioning control of flexible manipulators
- 深入浅出边缘云 | 4. 生命周期管理
- element-plus虚拟表格virtual-list组件中是怎么实现清理lodash.memoize缓存的?
- The paper manual becomes 3D animation in seconds, the latest research of Wu Jiajun of Stanford University, selected for ECCV 2022
- charles进行弱网测试(app弱网测试怎么做)
- Sentinel流量控制
- Redis与分布式:哨兵模式
- 2021 OWASP TOP 10 Vulnerability Guide
- Five dimensions to start MySQL optimization
猜你喜欢
随机推荐
TRACE32——基于SNOOPer的变量记录
Detailed guide to compare two tables using natural full join in SQL
The JVM a class loader
OpenShift 4 - 用 Operator 部署 Redis 集群
Prometheus之node_exporter性能监控信息采集含义
Jmeter常用的十大组件
我把问烂了的MySQL面试题总结了一下
MySql总结
MySQL [subquery]
sentinel与nacos持久化
R语言向前或者向后移动时间序列数据(自定义滞后或者超前的期数):使用dplyr包中的lag函数将时间序列数据向前移动一天(设置参数n为正值)
Redis与分布式:主从复制
OAuth2:四种授权方式
MySQL [aggregate function]
The role of /etc/profile, /etc/bashrc, ~/.bash_profile, ~/.bashrc files
NC | 中国农大草业学院杨高文组揭示发现多因子干扰会降低土壤微生物多样性的积极效应...
网线RJ45接口针脚[通俗易懂]
Sentinel热点参数限流
2021 OWASP TOP 10 漏洞指南
使用 Chainlink Keepers 实现智能合约函数的自动化执行