在Linux系统中,IP地址的配置信息通常保存在以下几个地方:
每个网络接口的配置信息通常保存在/etc/sysconfig/network-scripts/
目录下,文件名格式为ifcfg-<interface_name>
,例如ifcfg-eth0
或ifcfg-enp0s3
。
示例文件内容(ifcfg-eth0):
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
如果你使用的是NetworkManager这样的网络管理工具,IP地址的配置信息可能会保存在/etc/NetworkManager/system-connections/
目录下,文件名格式为<connection_name>.nmconnection
。
示例文件内容(Wired connection 1.nmconnection):
[connection]
id=Wired connection 1
uuid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
type=ethernet
interface-name=eth0
[ipv4]
method=manual
address1=192.168.1.100/24,192.168.1.1
路由表信息保存在/etc/iproute2/rt_tables
文件中,但实际的路由配置是通过ip route
命令动态管理的,不会持久化到文件中,除非手动保存。
如果使用DHCP获取IP地址,相关的配置信息会保存在/var/lib/dhcp/dhclient.<interface_name>.leases
文件中。
示例文件内容(dhclient.eth0.leases):
lease {
interface "eth0";
fixed-address 192.168.1.100;
option subnet-mask 255.255.255.0;
option routers 192.168.1.1;
...
}
某些发行版可能会在系统启动脚本中配置网络接口,例如/etc/rc.local
或/etc/init.d/networking
。
你可以使用以下命令查看当前系统的IP地址:
ip addr show
或者
ifconfig
如果你需要修改IP地址,可以直接编辑上述配置文件,然后重启网络服务或接口:
sudo systemctl restart network
或者使用NetworkManager:
sudo nmcli connection modify <connection_name> ipv4.addresses 192.168.1.101/24
sudo nmcli connection up <connection_name>
ip route
命令检查和修改路由配置。通过以上方法,你可以管理和查看Linux系统中的IP地址配置信息。
领取专属 10元无门槛券
手把手带您无忧上云