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
相关推荐
航Hang*1 分钟前
第七章:综合布线技术 —— 设备间子系统的设计与施工
网络·笔记·学习·期末·复习
智链RFID16 分钟前
RFID技术:企业效率革命新引擎
大数据·网络·人工智能·rfid
佩奇的技术笔记17 分钟前
TCP Keep-Alive 和 HTTP Keep-Alive区别
网络协议·tcp/ip·http
Wcowin18 分钟前
非对称密码
网络·密码学
航Hang*18 分钟前
第六章:综合布线技术 —— 干线子系统的设计与施工
网络·笔记·学习·期末·复习
航Hang*39 分钟前
第二章:综合布线技术 —— 综合布线常用器材和工具
网络·期末·复习
Exclusive_Cat1 小时前
先声医疗面经
网络
llilian_161 小时前
时间同步校时服务器配件清单及挑选攻略 校时时间服务器 网络时间同步装置
运维·服务器·网络
nvd112 小时前
通过 Gmail API 发送邮件的完整指南
服务器·网络
一叶星殇2 小时前
ASP.NET Core 后端如何通过 Nginx 获取真实客户端 IP 完整指南
服务器·tcp/ip·nginx