Ubuntu Server下的网络配置



Ubuntu Server下的网络配置
 
检查网络配置  www.2cto.com  
$ ifconfig
配置DHCP客户端
$ sudo vi /etc/network/interfaces
加入 iface eth0 inet dhcp
配置静态IP地址
$ sudo vi /etc/network/interfaces
eth0配置如下:  www.2cto.com  
auto eth0
address 192.168.0.88
netmask 255.255.255.0
gateway 192.168.0.1
让新配置生效
保存退出后,使用重启networking命令让新配置生效:
$ sudo /etc/init.d/networking restart
也可以重启网卡让新配置生效,优点是不影响其他网络接口:
$ sudo ifdown eth0
$ sudo ifup eth0
 
临时改变IP地址
$ sudo ifconfig eth0 192.168.1.111 netmask 255.255.255.0
当系统重启动后,后会恢复interfaces中的配置。
设置默认网关的方法也有两种:
1. 在interfaces文件中设置。
$ sudo vi /etc/network/interfaces
在eth0的相关配置下加入gateway,如:
auto eth0
iface eth0 inet static
address 192.168.1.123
netmask 255.255.255.0
gateway 192.168.1.1
2. 直接用命令设置:
删除当前缺省网关
$ sudo route del default gw
手工配置缺省网关
$ sudo route add default gw 192.168.1.1
查看路由信息
$ route
使用本方法,修改当即生效,重新启动后,则interfaces文件中的设置有效。
查看主机名
$ hosts
临时修改主机名
$ sudo hostname testserver
执行完命令后,即时生效。
永久修改主机名
$ sudo vi /etc/hostname
把新的主机名写入即可。当系统重启后,会读出此文件中主机名。
配置DNS服务器的地址,最多可以使用3个DNS服务器
$ sudo vi /etc/resolv.conf
nameserver 202.xx.xx.xx
nameserver 192.168.1.1
对”resolv.conf”的修改是即时生效的。可以使用nslookup命令进行DNS服务器查询,以验证”resolv.conf”配置文件。
 

相关内容

    暂无相关文章