• CentOS7.2 设置静态ip


    先找到配置文件:

    [root@localhost bin]# cd /etc/sysconfig/network-scripts
    [root@localhost network-scripts]# ls
    ifcfg-eno16777736  ifdown-ppp       ifup-ib      ifup-Team
    ifcfg-lo           ifdown-routes    ifup-ippp    ifup-TeamPort
    ifdown             ifdown-sit       ifup-ipv6    ifup-tunnel
    ifdown-bnep        ifdown-Team      ifup-isdn    ifup-wireless
    ifdown-eth         ifdown-TeamPort  ifup-plip    init.ipv6-global
    ifdown-ib          ifdown-tunnel    ifup-plusb   network-functions
    ifdown-ippp        ifup             ifup-post    network-functions-ipv6
    ifdown-ipv6        ifup-aliases     ifup-ppp
    ifdown-isdn        ifup-bnep        ifup-routes
    ifdown-post        ifup-eth         ifup-sit
    [root@localhost network-scripts]# gedit ifcfg-eno16777736

    开始配置是:

    TYPE="Ethernet"
    BOOTPROTO="dhcp"
    DEFROUTE="yes"
    PEERDNS="yes"
    PEERROUTES="yes"
    IPV4_FAILURE_FATAL="no"
    IPV6INIT="yes"
    IPV6_AUTOCONF="yes"
    IPV6_DEFROUTE="yes"
    IPV6_PEERDNS="yes"
    IPV6_PEERROUTES="yes"
    IPV6_FAILURE_FATAL="no"
    NAME="eno16777736"
    UUID="157c8fb5-23b3-414c-8519-25bef9b20a54"
    DEVICE="eno16777736"
    ONBOOT="yes"

    修改成:

    TYPE="Ethernet"
    #BOOTPROTO="dhcp"
    DEFROUTE="yes"
    PEERDNS="yes"
    PEERROUTES="yes"
    IPV4_FAILURE_FATAL="no"
    IPV6INIT="yes"
    IPV6_AUTOCONF="yes"
    IPV6_DEFROUTE="yes"
    IPV6_PEERDNS="yes"
    IPV6_PEERROUTES="yes"
    IPV6_FAILURE_FATAL="no"
    NAME="eno16777736"
    UUID="157c8fb5-23b3-414c-8519-25bef9b20a54"
    DEVICE="eno16777736"
    #ONBOOT="yes"
    
    #static assignment
    NM_CONTROLLED=no #表示该接口将通过该配置文件进行设置,而不是通过网络管理器进行管理
    ONBOOT=yes #开机启动
    BOOTPROTO=static #静态IP
    IPADDR=192.168.1.122 #本机地址
    NETMASK=255.255.255.0 #子网掩码
    GATEWAY=192.168.1.1 #默认网关

    修改/etc/sysconfig/network

    # Created by anaconda
    NETWORKING=yes
    GATEWAY=192.168.1.1
    DNS1=119.29.29.29
    DNS2=182.254.116.116

    然后重启服务即可

    service network restart

    一般这样就可以,但是如果有问题

    必须要在network-scripts里面的默认的文件里面添加HWADDR

    [root@localhost ~]# ip addr
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host 
           valid_lft forever preferred_lft forever
    2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        link/ether 00:0c:29:a7:a0:8c brd ff:ff:ff:ff:ff:ff
        inet 192.168.1.104/24 brd 192.168.1.255 scope global dynamic eno16777736
           valid_lft 7141sec preferred_lft 7141sec
        inet 192.168.1.122/24 brd 192.168.1.255 scope global secondary eno16777736
           valid_lft forever preferred_lft forever
        inet6 fe80::ac30:2bcb:e910:3ae/64 scope link 
           valid_lft forever preferred_lft forever
    3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
        link/ether 52:54:00:74:cb:1a brd ff:ff:ff:ff:ff:ff
        inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
           valid_lft forever preferred_lft forever
    4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000
        link/ether 52:54:00:74:cb:1a brd ff:ff:ff:ff:ff:ff

    先查看具体的 link/ether

    再赋值到eno16777736中

    比如:

    TYPE="Ethernet"
    #BOOTPROTO="dhcp"
    DEFROUTE="yes"
    PEERDNS="yes"
    PEERROUTES="yes"
    IPV4_FAILURE_FATAL="no"
    IPV6INIT="yes"
    IPV6_AUTOCONF="yes"
    IPV6_DEFROUTE="yes"
    IPV6_PEERDNS="yes"
    IPV6_PEERROUTES="yes"
    IPV6_FAILURE_FATAL="no"
    NAME="eno16777736"
    UUID="157c8fb5-23b3-414c-8519-25bef9b20a54"
    DEVICE="eno16777736"
    #ONBOOT="yes"
    
    #static assignment
    NM_CONTROLLED=no #表示该接口将通过该配置文件进行设置,而不是通过网络管理器进行管理
    ONBOOT=yes #开机启动
    BOOTPROTO=static #静态IP
    IPADDR=192.168.1.122 #本机地址
    NETMASK=255.255.255.0 #子网掩码
    GATEWAY=192.168.1.1 #默认网关
    
    HWADDR=00:0c:29:a7:a0:8c

    设定开机启动一个名为NetworkManager-wait-online服务,命令为:

    systemctl enable NetworkManager-wait-online.service

    重启服务。

    =======================================================================

    错误的经验:

    误以为是桥接模式,后来发现是NAT,没有设置虚拟机的 虚拟网络编辑器,坑!

    修改成:

    TYPE="Ethernet"
    BOOTPROTO="static"
    NM_CONTROLLED=no #表示该接口将通过该配置文件进行设置,而不是通过网络管理器进行管理
    
    DEFROUTE="yes"
    PEERDNS="yes"
    PEERROUTES="yes"
    IPV4_FAILURE_FATAL="no"
    IPV6INIT="yes"
    IPV6_AUTOCONF="yes"
    IPV6_DEFROUTE="yes"
    IPV6_PEERDNS="yes"
    IPV6_PEERROUTES="yes"
    IPV6_FAILURE_FATAL="no"
    NAME="eno16777736"
    UUID="157c8fb5-23b3-414c-8519-25bef9b20a54"
    DEVICE="eno16777736"
    ONBOOT="yes" #系统将在启动时开启该接口。
     
    IPADDR=192.168.1.122 #静态IP  
    GATEWAY=192.168.1.1 #默认网关  
    NETMASK=255.255.255.0 #子网掩码  
    #DNS1=192.168.7.1 #DNS 配置

    重启网络服务:

    service network restart  

    重启网络服务以后ok,但是重启系统以后还是变成了动态的,

    [root@localhost ~]# ip addr
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host 
           valid_lft forever preferred_lft forever
    2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        link/ether 00:0c:29:a7:a0:8c brd ff:ff:ff:ff:ff:ff
        inet 192.168.1.104/24 brd 192.168.1.255 scope global dynamic eno16777736
           valid_lft 6995sec preferred_lft 6995sec
        inet 192.168.1.122/24 brd 192.168.1.255 scope global secondary eno16777736
           valid_lft forever preferred_lft forever
        inet6 fe80::9283:cd42:a281:7a9b/64 scope link 
           valid_lft forever preferred_lft forever
    3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
        link/ether 52:54:00:74:cb:1a brd ff:ff:ff:ff:ff:ff
        inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
           valid_lft forever preferred_lft forever
    4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000
        link/ether 52:54:00:74:cb:1a brd ff:ff:ff:ff:ff:ff
    [root@localhost ~]# systemctl disable NetworkManager.service
    Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
    Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
    Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
    [root@localhost ~]# chkconfig network on
    [root@localhost ~]# systemctl stop NetworkManager
    [root@localhost ~]# systemctl restart network

    可以从上面看出两个ip

    192.168.1.104

    192.168.1.122

    解决方法:

    systemctl disable NetworkManager.service
    chkconfig network on
    systemctl stop NetworkManager
    systemctl restart network

    如果还出现

    [hongdada@localhost ~]$ systemctl status network.service
    ● network.service - LSB: Bring up/down networking
       Loaded: loaded (/etc/rc.d/init.d/network; bad; vendor preset: disabled)
       Active: failed (Result: exit-code) since 日 2017-12-03 23:05:01 CST; 2min 45s ago
         Docs: man:systemd-sysv-generator(8)
      Process: 3957 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=1/FAILURE)
    
    12月 03 23:05:01 localhost.localdomain network[3957]: RTNETLINK answers: File exists
    12月 03 23:05:01 localhost.localdomain network[3957]: RTNETLINK answers: File exists
    12月 03 23:05:01 localhost.localdomain network[3957]: RTNETLINK answers: File exists
    12月 03 23:05:01 localhost.localdomain network[3957]: RTNETLINK answers: File exists
    12月 03 23:05:01 localhost.localdomain network[3957]: RTNETLINK answers: File exists
    12月 03 23:05:01 localhost.localdomain network[3957]: RTNETLINK answers: File exists
    12月 03 23:05:01 localhost.localdomain systemd[1]: network.service: control process exited, code=exited status=1
    12月 03 23:05:01 localhost.localdomain systemd[1]: Failed to start LSB: Bring up/down networking.
    12月 03 23:05:01 localhost.localdomain systemd[1]: Unit network.service entered failed state.
    12月 03 23:05:01 localhost.localdomain systemd[1]: network.service fail

    那么。。。

    查看https://blog.csdn.net/kokuma/article/details/72876106

    可以使用journel -xe查看日志,一般就是修改配置文件里面的Name,DEVICE 为ens33

    首先使用ip addr查看网卡,然后查看ifconfig

    一般如果是第一次的,就是不是克隆的话,网卡名称为eno16777736,这里只要设定静态ip即可,如果是克隆的话,ip addr里面会发现网卡名称变成了ens33,这样的话,我们也必须在/etc/sysconfig/network-scripts/eno167777736文件里面把NAME,DEVICE里面的改成ens33,重新设定静态IP,重启即可。

    http://www.cnblogs.com/Leo_wl/p/5484136.html

    http://www.bbsmax.com/A/n2d9D39v5D/

    http://www.178linux.com/9928

  • 相关阅读:
    ASP.NET 读取FTP文件流
    ASP.NET XML序列化
    ASP.NET Core 微信支付(四)【支付结果通知回调(未按照官方步骤) APIV3】
    ASP.NET Core 微信支付(三)【查询订单 APIV3】
    pytest系列(四)
    pytest系列(五)
    2021金三银四
    2021金三银四
    requests- 处理 multipartform-data 类型的上传接口
    html5 video(html中播放视频的标签)
  • 原文地址:https://www.cnblogs.com/hongdada/p/6666932.html
Copyright © 2020-2023  润新知