美文网首页
linux开机启动网卡

linux开机启动网卡

作者: 贪恋红尘 | 来源:发表于2018-11-21 21:15 被阅读0次
    • linux安装完毕以后,我们必须对网卡进行配置才能使用。
    • 启用网卡,刚安装完毕,默认网卡为eth0
    ifup eth0
    
    • 查看网络配置配置
    ifconfig eth0
    

    [root@study ~]# ifconfig eth0
    eth0 Link encap:Ethernet HWaddr 00:0C:29:C2:5A:19
    inet addr:10.0.0.101 Bcast:10.0.0.255 Mask:255.255.255.0
    inet6 addr: fe80::20c:29ff:fec2:5a19/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:216 errors:0 dropped:0 overruns:0 frame:0
    TX packets:154 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:22500 (21.9 KiB) TX bytes:19609 (19.1 KiB)

    • 设置网卡开机启动
      查看网卡配置
    cat /etc/sysconfig/network-scripts/ifcfg-eth0
    

    [root@study ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0
    HWADDR=00:0C:29:C2:5A:19
    TYPE=Ethernet
    UUID=b13de4bc-fe1a-4a46-9eb6-21c07bc55ff7
    ONBOOT=no
    NM_CONTROLLED=yes
    BOOTPROTO=dhcp

    • ONBOOT=no配置为yes为开机启动网卡
      可以通过setup、vim编辑器和sed命令直接替换,
      前两种较为简单,这里使用sed命令进行替换。
    sed "s#ONBOOT=no#ONBOOT=yes#g" /etc/sysconfig/network-scripts/ifcfg-eth0
    

    [root@study ~]# sed "s#ONBOOT=no#ONBOOT=yes#g" /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0
    HWADDR=00:0C:29:C2:5A:19
    TYPE=Ethernet
    UUID=b13de4bc-fe1a-4a46-9eb6-21c07bc55ff7
    ONBOOT=yes
    NM_CONTROLLED=yes
    BOOTPROTO=dhcp

    sed -i "s#ONBOOT=no#ONBOOT=yes#g" /etc/sysconfig/network-scripts/ifcfg-eth0
    

    [root@study ~]# sed -i "s#ONBOOT=no#ONBOOT=yes#g" /etc/sysconfig/network-scripts/ifcfg-eth0

    [root@study ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0
    HWADDR=00:0C:29:C2:5A:19
    TYPE=Ethernet
    UUID=b13de4bc-fe1a-4a46-9eb6-21c07bc55ff7
    ONBOOT=yes
    NM_CONTROLLED=yes
    BOOTPROTO=dhcp

    • 配置完重启网卡
    ifdown eth0 && ifup eth0
    

    [root@study ~]# ifdown eth0 && ifup eth0
    Determining IP information for eth0... done.

    相关文章

      网友评论

          本文标题:linux开机启动网卡

          本文链接:https://www.haomeiwen.com/subject/vvdhqqtx.html