# 修改网络配置文件 /etc/network/interfaces (适用于Debian/Ubuntu系统)
# 这个文件用于配置静态IP地址、网关和DNS服务器等
# 示例:配置静态IP地址
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
# 或者使用命令行工具来临时修改IP地址(重启后失效)
# 使用ifconfig命令设置IP地址(需要安装net-tools包)
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
# 使用ip命令设置IP地址(推荐,无需额外安装)
sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip route add default via 192.168.1.1
# 配置DNS服务器
# 修改 /etc/resolv.conf 文件
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
echo "nameserver 8.8.4.4" | sudo tee -a /etc/resolv.conf
# 使用NetworkManager管理网络配置(适用于桌面环境)
# 设置静态IP地址
nmcli connection modify "Wired connection 1" ipv4.addresses 192.168.1.100/24
nmcli connection modify "Wired connection 1" ipv4.gateway 192.168.1.1
nmcli connection modify "Wired connection 1" ipv4.dns "8.8.8.8 8.8.4.4"
nmcli connection modify "Wired connection 1" ipv4.method manual
nmcli connection up "Wired connection 1"
# 查看当前网络配置
ip addr show
route -n
cat /etc/resolv.conf
以上代码展示了如何在Linux系统中配置网络,包括静态IP地址、网关和DNS服务器的设置。具体方法有通过修改配置文件、命令行工具以及使用NetworkManager进行管理。
上一篇:linux修改系统时间
下一篇:linux scp命令
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站