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
相关推荐
对讲机数码科普30 分钟前
从电路原理到协议栈:模拟对讲机与数字对讲机的技术内核拆解
运维·网络·架构·软件工程
福大大架构师每日一题1 小时前
mediamtx v1.21.2发布:UDP、JWT、RTSP、RTMP、HLS、WebRTC全面修复,稳定性与安全性再提升
网络协议·udp·webrtc
我送炭你添花1 小时前
ASA原理与电子维修实战:前言 一路修来,一路学习
运维·网络·学习
张小姐的猫1 小时前
【Linux】网络编程 —— 多路转接:epoll
linux·运维·网络
曹小强wxx1 小时前
Flutter 局域网设备发现:UDP 广播 + mDNS 双路合并,以及靠谱的在线判定与断线重连
物联网·网络协议·flutter
睡一觉就好了。1 小时前
linux网络编程基础
网络
花间相见1 小时前
【计算基础|网络09】TCP(上):三次握手与四次挥手
网络·网络协议·tcp/ip
北京盛世宏博2 小时前
多协议以太网温湿度变送器:Modbus TCP/UDP/SNMP 协议应用场景详解
单片机·tcp/ip·udp·传感器·温湿度
wdfk_prog2 小时前
LWIP教程 08:从 `tcp_write()` 到 ACK 清队列——TCP 数据发送、窗口与回调
网络·网络协议·tcp/ip
anew___2 小时前
《从零手写操作系统 (37):网络协议栈基础——Socket接口与TCP状态机》
网络·网络协议·tcp/ip