arm linux 添加静态ip,Linux静态IP设置(tim)-v2.0
设定IP
$sudo vi /etc/network/interfaces
auto lo
iface lo inet loopback
添加以下内容
auto eth0
iface eth0 inet static
address 192.168.0.221
netmask 255.255.255.0
gateway 192.168.0.1
保存,并关闭gedit。
这样,IP并没有立即生效。需要执行
$sudo /etc/init.d/networking restart
这时候就能ping到局域网中的电脑了。但是上不了Internet,是因为没有设置DNS的原因。
DNS信息保存在/etc/resolv.conf中,一旦更改,立即生效。
$sudo vi /etc/resolv.conf
nameserver 192.168.1.1
nameserver8.8.8.8
保存并关闭,现在就可以上网了。
不过Ubuntu 12.04每次重启后,/etc/resolv.conf里面设置的nameserver就被清空
如果想自己定义nameserver一直有效,那么有以下2个办法:
A在网卡的配置文件里面加:
iface eth0 inet static
address 192.168.3.3
netmask 255.255.255.0
gateway 192.168.3.1
dns-nameservers 114.114.114.1148.8.8.8
B修改resolvconf服务的配置文件: /etc/resolvconf/resolv.conf.d/base
清空原内容并写入以下内容
nameserver8.8.8.8
这样,在机器重启或resolvconf服务重启都可以保证配置会写到/etc/resolv.conf里面
其实/etc/resolv.conf里面一直都有提示,只是自己没注意看:
"DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN"
附网卡设置相关命令:
查看网卡信息:ifconfig
设定一个网卡IP:ifconfig eth0 192.168.1.10 netmask 255.255.255.0
重启网卡使设定生效:sudo /etc/init.d/networking restart
更改MAC地址:ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx
查看路由相关信息:route -n
增加网关
sudo route add default gw 192.168.10.1
删除网关
sudo routedeldefault
DNS服务器设置(Ubuntu)
1、两个免费好用的DNS服务器
googleDNS:
8.8.8.8;
8.8.8.4
openDNS
:
208.67.220.220;
208.67.222.222
2、查看本机DNS服务器
查看DNS server:nslookup www.baidu.com
更新dns设置,sudo resolvconf -u
临时设置ubuntu static ip并能上网
1.ip netmask
sudo ifconfig eth0 192.168.0.167 netmask 255.255.255.0
2.dns
sudo vi /etc/resolv.conf
添加
nameserver8.8.8.8
3.网关
sudo route add defalut gw 192.168.10.1
sudo routedeldefault
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
