p { margin-bottom: 0.08in; }pre.western { font-family: "文泉驿等宽正黑",monospace; }pre.cjk { font-family: "AR PL UMing HK",monospace; }pre.ctl { font-family: "文泉驿等宽正黑",monospace; }
查看当前
IP:
ifconfig
ubuntu 使用命令行获取动态
ip
dhclient eth0
/etc/network/interfaces
配置文件
一、使用命令设置Ubuntu
IP
地址
1,设置网卡
eth0的
IP地址和子网掩码
sudo ifconfig eth0 192.168.2.1
netmask 255.255.255.0
2,设置网关
sudo route add default gw
192.168.2.254
3,设置
DNS
修改
/etc/resolv.conf,在其中加入
nameserver
DNS的地址
1和
nameserver DNS的地址
2完成。
4,重启网络服务
sudo /etc/init.d/networking
restart
二、直接修改Ubuntu
IP
系统配置文件
Ubuntu
Ip的网络配置文件是:
/etc/network/interfaces
打开后里面可设置
DHCP或手动设置静态
ip。
1. 以
DHCP方式配置网卡
auto eth0 让网卡开机自动挂载
iface eth0 inet dhcp //设置 DHCP方式
用下面的命令使网络设置生效:
sudo /etc/init.d/networking restart 以上几步可以通过在命令行下直接输入下面的命令来实现(获取动态地址)sudo dhclient eth0
2. 为网卡配置静态
Ubuntu
IP地址
编辑文件 /etc/network/interfaces:
auto eth0 让网卡开机自动挂载
iface eth0 inet static //设置静态地址
address 192.168.2.1 //IP地址
gateway 192.168.2.254 //网关
netmask 255.255.255.0 //子网掩码
#network 192.168.2.0 //备注(子网号)
#broadcast 192.168.2.255 //备注(广播)
用下面的命令使网络设置生效:
sudo /etc/init.d/networking restart
3. 设定第二个
Ubuntu
IP地址
(虚拟
IP地址
)
编辑文件 /etc/network/interfaces:
在该文件中
添加
如下的行:
auto eth0:1 iface eth0:1 inet static address x.x.x.x netmask x.x.x.x network x.x.x.x broadcast x.x.x.x gateway x.x.x.x
用下面的命令使网络设置生效:
sudo /etc/init.d/networking
restart
4.
设置主机名称
(hostname)
使用下面的命令来查看当前主机的主机名称:
sudo
/bin/hostname
使用下面的命令来设置当前主机的主机名称:
sudo
/bin/hostname newname
系统启动时
,它会从
/etc/hostname来读取主机的名称。
5. 配置
DNS
首先,你可以在
/etc/hosts中加入一些主机名称和这些主机名称对应的
IP地址,这是简单使用本机的静态查询。
要访问
DNS
服务器来进行查询
,需要设置
/etc/resolv.conf文件,假设
DNS服务器的
IP地址是
192.168.2.2,
那么
/etc/resolv.conf文件的内容应为:
search
chotim.com
nameserver 192.168.2.2
6.手动重启网络服务:
sudo
/etc/init.d/networking restart
返回结果如下:
*Reconfiguring
network interfaces… [OK]