当前位置:网站首页>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-managerIs 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 networkingThe 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使用yamlFormat 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]
注意yamlFiles 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
边栏推荐
- TRACE32——基于SNOOPer的变量记录
- The 232-layer 3D flash memory chip is here: the single-chip capacity is 2TB, and the transmission speed is increased by 50%
- The role of /etc/profile, /etc/bashrc, ~/.bash_profile, ~/.bashrc files
- OpenShift 4 - Customize RHACS security policies to prevent production clusters from using high-risk registry
- Essential Learning for Getting Started with Unity Shader - Transparency Effect
- The use of thread pool two
- Nuget package and upload tutorial
- R语言检验样本是否符合正态性(检验样本是否来自一个正态分布总体):shapiro.test函数检验样本是否符合正态分布(normality test)
- Groupid(artifact id)
- Recommendation System - Recall Phase - 2013: DSSM (Twin Towers Model) [Embedding (Semantic Vector) Recall] [Microsoft]
猜你喜欢

In the future, the interviewer asks you why it is not recommended to use Select *, please answer him out loud!

"Listen to me, thank you" can be said in ancient poetry?Tsinghua University has developed an artifact of "Searching Sentences According to Meaning", which can search for the famous sayings you want wi

名创优品斥资6.95亿购买创始人叶国富所持办公楼股权

The 232-layer 3D flash memory chip is here: the single-chip capacity is 2TB, and the transmission speed is increased by 50%

Small test knife: Go reflection helped me convert Excel to Struct

Description of Hikvision camera streaming RTSP address rules

OpenShift 4 - Deploy Redis Cluster with Operator

五个维度着手MySQL的优化

基于最小二乘法和SVM从天气预报中预测太阳能发电量(Matlab代码实现)

I summed up the bad MySQL interview questions
随机推荐
力扣:714. 买卖股票的最佳时机含手续费
The JVM a class loader
Trigonometric identity transformation formula
使用 PyTorch 检测眼部疾病
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(caption、添加、修改可视化图像的题注、脚注内容)
jvm 一之 类加载器
OAuth2:微服务权限校验Session共享
微信聊天记录中搜索红包
Node实现数据加密
763.划分字母区间——之打开新世界
redhat/openssl generates a self-signed ca certificate and uses it
梅克尔工作室-第一次
The use of thread pool two
我把问烂了的MySQL面试题总结了一下
Resnet&API
基于极限学习机(ELM)进行多变量用电量预测(Matlab代码实现)
redhat/openssl生成自签ca证书并使用
谷歌CTS测试(cta测试)
最小费用最大流问题详解
五个维度着手MySQL的优化