本帖最后由 水精灵 于 2024-3-8 13:40 编辑
一、设置静态IP 1.配置文件路径/etc/network/interfaces root@ELF1:~# vi /etc/network/interfaces
2.根据实际情况进行配置修改 例如修改eth0的IP为192.168.1.232: # Wired or wireless interfaces auto eth0 #iface eth0 inet dhcp #iface eth1 inet dhcp iface eth0 inet static address 192.168.1.232 netmask 255.255.255.0 # gateway 192.168.0.1 hwaddress ether aa:cc:dd:ee:ff:dd 效果如下:
3.设置DNS root@ELF1:~# vi /etc/autorun.sh 添加如下内容: echo "nameserver 8.8.8.8" >/etc/resolv.conf 效果如下:
4.重启网络 root@ELF1:~# /etc/init.d/networking restart
5.查看eth0的IP root@ELF1:~# ifconfig eth0 IP设置成功。
二、设置动态IP 设置动态获取IP时,只需将/etc/network/interfaces文件改为如下形式,其它步骤与设置静态IP相同。 例如设置eth0为动态获取IP: # Wired or wireless interfaces auto eth0 iface eth0 inet dhcp #iface eth1 inet dhcp #iface eth0 inet static # address 192.168.1.232 # netmask 255.255.255.0 # gateway 192.168.0.1 # hwaddress ether aa:cc:dd:ee:ff:dd 效果如下: |