1. 程式人生 > >linux網卡的開啟

linux網卡的開啟

CA code cas span ppp net 技術分享 IV roo

一:文件配置網卡在開機時,自動啟用

首先我們使用 ip addr查看IP信息

[root@redhat2 network-scripts]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500
qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:85:58:f1 brd ff:ff:ff:ff:ff:ff inet6 fe80::20c:29ff:fe85:58f1/64 scope link valid_lft forever preferred_lft forever

可以看出第一個是本地回環地址,第二個是我們使用的網卡信息。一般沒人是沒有inet等信息的。因為默認是不啟動網卡的。

[root@redhat2 ~]# cd /etc/sysconfig/network-scripts/  #網絡配置文件位置
[root@redhat2 network
-scripts]# ls ifcfg-eth0(可以對網卡進行設置) ifdown-isdn ifup-aliases ifup-plusb init.ipv6-global ifcfg-lo ifdown-post ifup-bnep ifup-post net.hotplug ifdown ifdown-ppp ifup-eth ifup-ppp network-functions ifdown-bnep ifdown-routes ifup-ippp ifup-routes network-functions-ipv6 ifdown
-eth ifdown-sit ifup-ipv6 ifup-sit ifdown-ippp ifdown-tunnel ifup-isdn ifup-tunnel ifdown-ipv6 ifup ifup-plip ifup-wireless [root@redhat2 network-scripts]#

查看配置文件

[root@redhat2 network-scripts]# vim ifcfg-eth0 


DEVICE="eth0"
BOOTPROTO="dhcp"
HWADDR="00:0C:29:85:58:F1"
NM_CONTROLLED="yes"
ONBOOT="no"  #默認是啟動時不開啟網卡,我們可以將這個設置為yes
TYPE="Ethernet"
UUID="dd04bdab-73cc-41aa-94a4-1837bff7c726"

然後重啟網絡

service network restart

發現有IP了

[root@redhat2 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:85:58:f1 brd ff:ff:ff:ff:ff:ff
    inet 192.168.218.129/24 brd 192.168.218.255 scope global eth0
    inet6 fe80::20c:29ff:fe85:58f1/64 scope link 
       valid_lft forever preferred_lft forever
[root@redhat2 ~]# 

上面獲取的地址,是我們自己在虛擬機的虛擬網絡編輯器中設置的

技術分享圖片

二:手動命令啟動和關閉ifup eth0和ifdown eth0

ifup eth0    是啟動網卡
ifdown  eth0    是關閉網卡

推文:ifconfig,ifup,ifdown

linux網卡的開啟