Linux 手动配置网络 IP

技术 · 2022-09-10

有时候我们只是需要临时配置一个 IP 来测试网络环境或者编写脚本使用,这时修改配置文件就略显繁琐了,此时就可以手动配置网络 IP 来实现。
查看当前网络接口的状态:

ifconfig

确定要配置的网络接口,通常为 eth0 或 enp0sX,禁用该网络接口:

ifconfig <interface> down

设置 IP 地址、子网掩码和默认网关:

ifconfig <interface> <ip_address> netmask <subnet_mask>
route add default gw <default_gateway>

最后启用网络接口:

ifconfig <interface> up

如果需要持久化网络配置,CentOS 还是推荐使用 nmtui,Ubuntu 使用 netplan。

Linux 运维 服务器 网络
Theme Jasmine. 由 Cloudflare 提供 CDN 加速 ICP 20232321