ubuntu设置静态ip

1、打开配置文件:

$ sudo vim /etc/network/interfaces

2、修改文件内容:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

auto eth0

iface eth0 inet static
address 192.168.1.104
netmask 255.255.255.0
gateway 196.168.1.1

3、重启网络服务:

$ sudo /etc/init.d/networking restart

4、查看ip是否设置成功:

$ ifconfig eth0
eth0       Link encap:Ethernet  HWaddr f0:4d:a2:72:f8:a4  
          inet addr:192.168.1.104  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::f24d:a2ff:fe72:f8a4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:28590 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9808 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:36485768 (36.4 MB)  TX bytes:893485 (893.4 KB)
          Memory:91120000-9113ffff 

 

5、重启系统:

$ sudo reboot

 

6、ping局域网检测:

$ ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.384 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.287 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.271 ms
64 bytes from 192.168.1.1: icmp_seq=4 ttl=64 time=0.255 ms

 

 

7、使用dhcp v4(动态获取DNS):

$ sudo dhclient -4 eth0

8、ping外网检测:

$ ping www.baidu.com
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39: icmp_seq=1 ttl=56 time=6.33 ms
64 bytes from 14.215.177.39: icmp_seq=2 ttl=56 time=7.54 ms
64 bytes from 14.215.177.39: icmp_seq=3 ttl=56 time=7.02 ms
64 bytes from 14.215.177.39: icmp_seq=4 ttl=56 time=7.94 ms


 

posted @ 2017-10-10 17:22  LeeAaron  阅读(358)  评论(0编辑  收藏  举报