由于一般的ubuntu服务器都没有安装图形界面,所以许多东西都是要经过修改文件来配置。设置ip也是如此。设置ip要通过/etc/network/interfaces文件。
sudo vi /etc/network/interfaces 打开配置文件,内容显示如下(#号后面的内容是注释)
#This file describes the network interfaces available on your system(这个文件描述了你的系统可以使用的网络适配器)
#and how to activate them. For more information, see interfaces(5).(并且描述了如何激活他们,需要更多的信息看interfaces(5))
#The loopback network interface(回环网络适配器)
autolo(auto表示开机自动激活的)
ifacelo inet loopback(这两项肯定有,只要tcp/ip协议配置正确,一般不用管)
#The primary network interface(主要的网络适配器)
autoeth0(表示开机自动激活的)
ifaceeth0 inet static(iface后面跟需要配置的适配器,inet后面跟获得ip的形式有两种dhcp和static,其中dhcp表示动态获取,static表示静态获取)
address 59.65.232.205(ip地址)
netmask 255.255.255.0(子网掩码)
network 59.65.232.0(网段)
broadcast 59.65.232.255(广播)
gateway 59.65.232.254(网关)
# dns-* options are implemented by theresolvconf package, if installed
dns-nameservers 202.204.65.5(设置dns)
其中dns也可以在/etc/resolv.conf文件中进行设置。格式
nameserverx.x.x.x
其中的eth0不一定所有的计算机都是一样。看你的网卡具体情况。
ifconfig命令查看当前活跃的网络适配器。
ifconfig–a查看计算机上所有的网络适配器,包括不活跃的(如果有一个以上的网络适配器,且其中有不活跃的)。
此文只是提供标准的配置格式,读者要会举一反三。