Linux静态IP配置

Linux静态IP配置

linux获得ip地址有两种方式

1.动态获得 dhcp 动态分配ip地址 (动态主机配置协议 作用:给其他机器分配ip地址、子网掩码、网关、DNS服务器地址)应用层

2.静态配置(手工配置)

linux里如何静态配置ip地址

LAN WAN WLAN:wireless local area network

IP internet protocol 互联网协议

nmcli : networkmanager client 网络管理服务的客户端命令给用户使用的

查看ip地址

bash 复制代码
ip add

查看route配置

bash 复制代码
ip route

Rocky Linux配置

修改配置文件 /etc/NetworkManager/system-connections

bash 复制代码
vim /etc/NetworkManager/system-connections/ens160.nmconnection
shell 复制代码
[connection]
id=ens160
uuid=ca09b8b6-256e-35e8-9ab5-7df4601503e7
type=ethernet
autoconnect-priority=-999
interface-name=ens160
timestamp=1763737876

[ethernet]

[ipv4]
#method=auto
method=manual
addresses1=192.168.154.136/24,192.168.154.2
dns=114.114.114.114;

[ipv6]
addr-gen-mode=eui64
method=auto

[proxy]
shell 复制代码
[root@web-nginx1 system-connections]# chmod 600 ens160.nmconnection 
[root@web-nginx1 system-connections]# nmcli connection reload
[root@web-nginx1 system-connections]# nmcli connection up ens160
bash 复制代码
nmcli  查看本机的网络连接
nmcli d down ens33
nmcli d up ens33

查看DNS服务器的地址

bash 复制代码
vim /etc/resolv.conf

关闭(开启)所有的网络连接

复制代码
nmcli n off  禁用网络连接
nmcli n on   开启网络连接
nmcli c down ens33  禁用ens33连接
nmcli c up  ens33  开启ens33连接

[root@TomDeng ~]# nmcli n
enabled
# 网络可以使用

ubunu配置

bash 复制代码
vim /etc/netplan/50-cloud-init.yaml
复制代码
# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        ens33:
            dhcp4: no
            addresses: [192.168.154.160/24]
            routes:
              - to: default
                via: 192.168.154.2
            nameservers: 
              addresses: [114.114.114.114]
    version: 2
~                 

更改完配置之后执行

bash 复制代码
netplan apply  # 执行完后即可更改配置
复制代码
查看dns服务器地址
tom@tom:~$ resolvectl status
Global
         Protocols: -LLMNR -mDNS -DNSOverTLS
                    DNSSEC=no/unsupported
  resolv.conf mode: stub

Link 2 (ens33)
    Current Scopes: DNS
         Protocols: +DefaultRoute -LLMNR -mDNS
                    -DNSOverTLS
                    DNSSEC=no/unsupported
Current DNS Server: 114.114.114.114
       DNS Servers: 114.114.114.114
相关推荐
Jony_3 天前
高可用移动网络连接
网络协议
chilix3 天前
Linux 跨网段路由转发配置
网络协议
DianSan_ERP5 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
呉師傅5 天前
火狐浏览器报错配置文件缺失如何解决#操作技巧#
运维·网络·windows·电脑
gihigo19985 天前
基于TCP协议实现视频采集与通信
网络协议·tcp/ip·音视频
2501_946205525 天前
晶圆机器人双臂怎么选型?适配2-12寸晶圆的末端效应器有哪些?
服务器·网络·机器人
linux kernel5 天前
第七部分:高级IO
服务器·网络
数字护盾(和中)5 天前
BAS+ATT&CK:企业主动防御的黄金组合
服务器·网络·数据库
~远在太平洋~5 天前
Debian系统如何删除多余的kernel
linux·网络·debian
龙仔7255 天前
在麒麟V10服务器安全加固,sshd防暴力破解加固,实现“密码错误3次封IP”的需求
服务器·tcp/ip·安全