Fedora Linux如何设置网卡自动获取网络地址

Fedora Linux如何设置网卡自动获取网络地址

    Fedora Linux如何设置网卡自动获取网络地址
    [日期:2011-01-11]     来源:Linux社区  作者:bluedream_119

    第一步:激活网卡

        Fedora Linux系统装好后默认的网卡是eth0,用下面的命令将这块网卡激活。
    # ifconfig eth0 up  

    第二步:设置网卡进入系统时启动
        想要每次开机就可以自动获取IP地址上网,就要设置网络服务在系统启动时也启动。Linux有一点与windows不同的是很多服务默认是停止的,而且你在某次使用该服务时启动这个服务,但是没设置它为默认启动,则下次进入系统这个服务依然是停止的。下面是设置网络服务在系统启动时也启动的方法。

        使用chkconfig命令让网络服务在系统启动级别是2345时默认启动。

    # chkconfig --level 2345 network on

    第三步:修改网卡文件ifcfg-eth0
        修改ifcfg-eth0文件,设置ONBOOT的值为yes,让网络服务启动时使用该网卡。设置BOOTPROTO的值为dhcp,让网卡从DHCP服务器自动获取IP地址。

    # vi /etc/sysconfig/network-scripts/ifcfg-eth0

    ONBOOT=yes
    BOOTPROTO=dhcp

    总结:
        通常情况下第三步是最重要的,因为大部分Linux系统默认网络服务是系统启动时也启动的,网卡也是启用的,只要设置好第三步,然后使用下面的命令启动网络服务就OK。

    # service network start

        配置静态IP地址上网与动态IP地址上网同出一辙,修改ifcfg-eth0,然后用命令service network retart重启网络服务。

    DEVICE=eth0
    IPADDR=192.168.1.100
    NETMASK=255.255.255.0
    GATEWAY=192.168.1.1
    DNS=8.8.8.8
    BOOTPROTO=static
    ONBOOT=yes

    进行以上三步后,可以获得ip了。但后来又出现不能获取ip,并且重复以上也没作用。

    使用

    #dhclient eth0

    备注:

    Linux Force DHCP client (dhclient) to renew ip address

    Linux renew ip command
    $ sudo dhclient -r //release ip 释放IP
    $ sudo dhclient //获取IP

    Now obtain fresh IP:
    $ sudo dhclient
    There is no need to restart network service. Above command should work with any Linux distro such as RHEL, Fedora, CentOS, Ubuntu and others. On a related note you can also try out the following commands:
    # ifdown eth0
    # ifup eth0
    # /etc/init.d/network restart
    OR
    # /etc/init.d/networking restart

原文地址:https://www.cnblogs.com/lexus/p/2367621.html