记一次centos改静态ip

记一次centos改静态ip

1.修改/etc/sysconfig/network-scripts/网卡文件

eg:vi /etc/sysconfig/network-scripts/ifcfg-ens33

TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
#BOOTPROTO="dhcp"
#静态ip配置,根据自己的VMware网段进行设置
BOOTPROTO="static"
IPADDR="192.168.25.137" #这里设置IP地址
NETMASK="255.255.255.0" #设置子网掩码
GATEWAY="192.168.25.2" #设置网关
DNS1="8.8.8.8"  #设置dns  域名解析服务器

DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="4f9a5611-f3c9-447c-9df8-02f6b5d6825b"
DEVICE="ens33"
#设置静态ip 需要将ONBOOT的值改为yes
#ONBOOT="no"
ONBOOT="yes"


2.重启网络,网卡

#重启网卡
ifconfig ens33 down
ifconfig ens33 up

#重启网络
service network restart      
#或者可以service network stop  然后 service network start     
#systemctl  restart network.service

重启后一般可以看见静态ip
设置成功

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.25.137  netmask 255.255.255.0  broadcast 192.168.25.255
        inet6 fe80::a91d:cbe4:2cbb:49cc  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:cc:43:c8  txqueuelen 1000  (Ethernet)
        RX packets 1114  bytes 276650 (270.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 246  bytes 31097 (30.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 64  bytes 5568 (5.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 64  bytes 5568 (5.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

然后可以ping 百度网址。

ping www.baidu.com

PING www.wshifen.com (103.235.46.39) 56(84) bytes of data.
64 bytes from 103.235.46.39 (103.235.46.39): icmp_seq=1 ttl=128 time=65.6 ms
64 bytes from 103.235.46.39 (103.235.46.39): icmp_seq=2 ttl=128 time=65.5 ms
64 bytes from 103.235.46.39 (103.235.46.39): icmp_seq=3 ttl=128 time=66.2 ms
64 bytes from 103.235.46.39 (103.235.46.39): icmp_seq=4 ttl=128 time=65.4 ms
64 bytes from 103.235.46.39 (103.235.46.39): icmp_seq=5 ttl=128 time=65.6 ms
^C
--- www.wshifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4007ms
rtt min/avg/max/mdev = 65.420/65.708/66.285/0.440 ms

如果能ping通说明网络通了。

如果不能ping通,进一步排查问题,先ping 网关地址 (上面配置文件的设置项)。

ping 192.168.25.2

PING 192.168.25.2 (192.168.25.2) 56(84) bytes of data.
64 bytes from 192.168.25.2: icmp_seq=1 ttl=128 time=0.140 ms
64 bytes from 192.168.25.2: icmp_seq=2 ttl=128 time=0.145 ms
64 bytes from 192.168.25.2: icmp_seq=3 ttl=128 time=0.275 ms
64 bytes from 192.168.25.2: icmp_seq=4 ttl=128 time=0.900 ms
64 bytes from 192.168.25.2: icmp_seq=5 ttl=128 time=0.255 ms
^C
--- 192.168.25.2 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4002ms
rtt min/avg/max/mdev = 0.140/0.343/0.900/0.283 ms

能通就可以确定网关设置正确,反之 网关设置错误,重新设置网关。

假如网关能ping通,就开始进行下一步

systemctl stop NetwrokManager 

systemctl disable NetworkManager

#然后重启网络
service network restart   

在ping查看网络是否通路,如果不是则查看/etc/resolv.conf 文件中是否有nameserver

# Generated by NetworkManager
search localdomain
nameserver 8.8.8.8
~                                                                                                                        
~                                                                                                                        
~                                                                                                                                                                                                                                                                                         
                                                                                                                                                    1,1          全部

没有则可以手动加上,重启机器。
假如最后还是不能网络通路,最后建议进行图形界面设置静态ip。server 版本好像有个像boot一样的界面也可以设置ip,这里我没找到。

上一篇:各类GC日志格式


下一篇:AD142A录变音芯片的程序实现原理以及部分程序截图