Linux开机自动联网

作者:海鹰
此教程讲述让CentOS在开机的时候自动联网
版权所有,未经允许,请勿随意转载。

1. 操作

1. 进入网卡配置目录
1
cd /etc/sysconfig/network-scripts/
2. 查看当前网卡的配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
ifconfig

test: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.8.150 netmask 255.255.255.0 broadcast 192.168.8.255
inet6 fe80::20c:29ff:fe48:8f05 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:48:8f:05 txqueuelen 1000 (Ethernet)
RX packets 2793091 bytes 416875435 (397.5 MiB)
RX errors 0 dropped 3711 overruns 0 frame 0
TX packets 340553 bytes 46409458 (44.2 MiB)
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 0 (Local Loopback)
RX packets 722053 bytes 47173052 (44.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 722053 bytes 47173052 (44.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:91:85:29 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
3. 选择对应的网卡配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ls -al

total 244
drwxr-xr-x. 2 root root 4096 Aug 5 15:19 .
drwxr-xr-x. 6 root root 4096 Aug 5 15:19 ..
-rw-r--r--. 1 root root 332 Aug 5 14:53 ifcfg-test
-rw-r--r--. 1 root root 254 Sep 16 2015 ifcfg-lo
lrwxrwxrwx. 1 root root 24 Aug 5 10:19 ifdown -> ../../../usr/sbin/ifdown
-rwxr-xr-x. 1 root root 627 Sep 16 2015 ifdown-bnep
-rwxr-xr-x. 1 root root 5817 Sep 16 2015 ifdown-eth
-rwxr-xr-x. 1 root root 6196 Dec 1 2015 ifdown-ib
-rwxr-xr-x. 1 root root 781 Sep 16 2015 ifdown-ippp
-rwxr-xr-x. 1 root root 4201 Sep 16 2015 ifdown-ipv6
......

# 在第2步可以看到网卡的配置名为test
# 因此,ifcfg-test就是即将进行修改的文件
4. 找到对应的配置
1
2
3
4
5
6
7
8
vi ifcfg-test

# 找到ONBOOT
# 默认情况下,ONBOOT=no,将值修改为yes即可

ONBOOT=yes

# 修改完保存退出即可

2. 结语

本教程到此结束,欢迎指正,互相交流。
版权所有,未经允许,请勿随意转载。