系统环境:ubuntu 12.0 server
1,用ifconfig -a插卡网卡有几种类型。用ifconfig查看系统认出的网卡(本机是只用 lo , 没有eth0)
2,首先为了显示eth0。
#vi /etc/network/interfaces
在
auto lo
iface lo inet loopback
下行写入:
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.33
gateway 192.168.0.1
netmask 255.255.255.0
#network 192.168.0.0
#broadcast 192.168.0.255
3,#cd /etc/resolvconf/resolv.conf.d/
#vi base
添加 nameserver 8.8.8.8
nameserver 8.8.4.4
4,#sudo /etc/init.d/networking restart
重启网卡。
5,再ifconfig 一般就可以看到eth0网卡信息。(不行重启既可)
6,重启后可以查看resolv.conf
#cat /etc/resolv.conf
就看到了我们刚在固定的dns地址。(网上教程老是先改resolv.conf ,明明知道重启后会失效的。。。无语了)
************************************************************************
如果ifconfig -a 有eth0,还有eth1。如何区分有线网插在eth0还是eth1呢?
本人方法:修改/etc/network/interface
在
auto lo
iface lo inet loopback
下行写入:
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.33
gateway 192.168.0.1
netmask 255.255.255.0
#network 192.168.0.0
#broadcast 192.168.0.255
# The primary network interface
auto eth1
iface eth1 inet static
address 192.168.0.33
gateway 192.168.0.1
netmask 255.255.255.0
#network 192.168.0.0
#broadcast 192.168.0.255
然后#sudo /etc/init.d/networking restart
ifconfig 查看eth1是否出现(不行重启)
出现后:分别试试 #route add default gw 192.168.0.1 dev eth0 和#route add defualt gw 192.168.0.1 dev eth1(未差网线的会有提示,网管正确的无异常)
*****************************************************************************************************
如果是在局域网(网关:192.168.1.1.),想用DHCP 自动分配ip地址:
则修改vi /etc/network/interfaces
在
auto lo
iface lo inet loopback
下行写入:
# The primary network interface
auto eth0
iface eth0 inet dhcp
然后sudo /etc/init.d/networking restart
再用ifconfig 查看ip相关信息。(不行重启)
局域网出现ping不通外网:ping www.baidu.com 出现:unknow host
输入命令:#route add default gw 192.168.1.1 dev eth0 既可以解决。
但好像不能永久解决,你可以试试修改 /etc/init.d/resolvconf/resolv.conf.d/base 文件,添加一段
nameserver 192.168.1.1
重启网卡或者重启。
****************************************************************************************************
2014,9月1 &Am3
1,用ifconfig -a插卡网卡有几种类型。用ifconfig查看系统认出的网卡(本机是只用 lo , 没有eth0)
2,首先为了显示eth0。
#vi /etc/network/interfaces
在
auto lo
iface lo inet loopback
下行写入:
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.33
gateway 192.168.0.1
netmask 255.255.255.0
#network 192.168.0.0
#broadcast 192.168.0.255
3,#cd /etc/resolvconf/resolv.conf.d/
#vi base
添加 nameserver 8.8.8.8
nameserver 8.8.4.4
4,#sudo /etc/init.d/networking restart
重启网卡。
5,再ifconfig 一般就可以看到eth0网卡信息。(不行重启既可)
6,重启后可以查看resolv.conf
#cat /etc/resolv.conf
就看到了我们刚在固定的dns地址。(网上教程老是先改resolv.conf ,明明知道重启后会失效的。。。无语了)
************************************************************************
如果ifconfig -a 有eth0,还有eth1。如何区分有线网插在eth0还是eth1呢?
本人方法:修改/etc/network/interface
在
auto lo
iface lo inet loopback
下行写入:
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.33
gateway 192.168.0.1
netmask 255.255.255.0
#network 192.168.0.0
#broadcast 192.168.0.255
# The primary network interface
auto eth1
iface eth1 inet static
address 192.168.0.33
gateway 192.168.0.1
netmask 255.255.255.0
#network 192.168.0.0
#broadcast 192.168.0.255
然后#sudo /etc/init.d/networking restart
ifconfig 查看eth1是否出现(不行重启)
出现后:分别试试 #route add default gw 192.168.0.1 dev eth0 和#route add defualt gw 192.168.0.1 dev eth1(未差网线的会有提示,网管正确的无异常)
*****************************************************************************************************
如果是在局域网(网关:192.168.1.1.),想用DHCP 自动分配ip地址:
则修改vi /etc/network/interfaces
在
auto lo
iface lo inet loopback
下行写入:
# The primary network interface
auto eth0
iface eth0 inet dhcp
然后sudo /etc/init.d/networking restart
再用ifconfig 查看ip相关信息。(不行重启)
局域网出现ping不通外网:ping www.baidu.com 出现:unknow host
输入命令:#route add default gw 192.168.1.1 dev eth0 既可以解决。
但好像不能永久解决,你可以试试修改 /etc/init.d/resolvconf/resolv.conf.d/base 文件,添加一段
nameserver 192.168.1.1
重启网卡或者重启。
****************************************************************************************************
2014,9月1 &Am3