ubuntu的网络配置文件是:/etc/network/interfaces
打开后里面可设置DHCP或手动设置静态ip。前面auto eth0,让网卡开机自动挂载。
1. 以DHCP方式配置网卡
打开配置文件,编辑下面的行:
auto eth0
iface eth0 inet dhcp
2. 为网卡配置静态IP地址
打开配置文件,编辑下面的行:
auto eth0 #指明网卡eth0在系统启动时自动加载
iface eth0 inet static #指明eth0采用ipv4地址,inet表示ipv4地址,inet6表示ipv6地址;static表示静态,dhcp表示动态
address 192.168.1.3
gateway 192.168.1.1
netmask 255.255.255.0
#network 192.168.2.0
#broadcast 192.168.2.255
3.设置主机名称(hostname)
修改/etc/hostname文件的内容为你自己主机的名称。
4.配置dns
编辑/etc/resolv.conf文件内容,如:
nameserver 61.128.128.68
nameserver 61.128.192.68
5.配置主机
在/etc/hosts中加入一些主机名称和这些主机名称对应的IP地址,如:
192.168.1.138 master
192.168.1.139 slave01
用下面的命令使网络设置生效:
sudo /etc/init.d/networking restart
返回结果如下:
*Reconfiguring network interfaces… [OK]