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