欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Linux 配置静态IP

程序员文章站 2022-07-14 10:20:53
...

##前提请确认网络连接方式为:桥接

###修改网卡eth0

vim /etc/sysconfig/network-scripts/ifcfg-eth0 
++++++++++++++++++++++++++++++++
DEVICE="eth0"
BOOTPROTO="static" #将原来的值“dhcp”改为“static”
HWADDR="00:0C:29:F2:4E:96"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="b68b1ef8-13a0-4d11-a738-1ae704e6a0a4"
IPADDR=192.168.1.16    #你需要定义的IP地址
#以下两个的值如果不清楚的话,可以打开你本地的电脑,--》控制面板\所有控制面板项\网络和共享中心\本地连接\详细信息
NETMASK=255.255.255.0 #子网掩码
GATEWAY=192.168.1.1    #默认网关,
++++++++++++++++++++++++++++++++

保存退出
重启网络服务

service network restart

检查一下状态

ifconfig -a
+++++++++++++++++++++++++++++++++
eth0      Link encap:Ethernet  HWaddr 00:0C:29:F2:4E:96  
          inet addr:192.168.1.16  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fef2:4e96/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:17017 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9586 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:7803412 (7.4 MiB)  TX bytes:1613751 (1.5 MiB)
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:21844 errors:0 dropped:0 overruns:0 frame:0
          TX packets:21844 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2042507 (1.9 MiB)  TX bytes:2042507 (1.9 MiB)
+++++++++++++++++++++++++++++++++

到了这里,请ping一下外网

ping baidu.com

我遇到两个情况:
1)ping通了,oh yeah!
2)报错:ping:unknow host baidu.com好吧,我的解决方法是:dhclient
敲了这个命令后,再ping一次
PING baidu.com (180.149.132.47) 56(84) bytes of data.  64 bytes from 180.149.132.47: icmp_seq=1 ttl=54 time=38.3 ms  64 bytes from 180.149.132.47: icmp_seq=2 ttl=54 time=38.7 ms  64 bytes from 180.149.132.47: icmp_seq=3 ttl=54 time=49.7 ms  64 bytes from 180.149.132.47: icmp_seq=4 ttl=54 time=38.1 ms  64 bytes from 180.149.132.47: icmp_seq=5 ttl=54 time=37.9 ms  64 bytes from 180.149.132.47: icmp_seq=6 ttl=54 time=38.3 ms
 我是这样解决的
还有人是这样:配置静态IP之后reboot

3)还有一个情况就是,ping 外网IP可以,但是无法ping域名。我的解决办法是:设置DNS

vim /ect/resolv.conf
nameserver 114.114.114.114 //这个值我是在本地连接的状态信息里找到的

保存之后退出,再ping!

相关标签: linux配置静态IP