---
title: "linux 网卡配置中的auto和allow-hotplug"
url: "https://lerry.me/post/2011/12/auto-and-allow-hotplug-in-linux"
date: 2011-12-10T15:43:00.000Z
updated: 2026-08-25T08:45:59.929Z
tags:
  - "Linux"
  - "Debian"
language: zh-CN
---

# linux 网卡配置中的auto和allow-hotplug

今天要配置服务器增加一个网线，因为服务器本来有两个网卡，但只用了一个，另一个没插上网线，为了给服务器上的某个服务增加带宽，决定让其单独使用一块网卡。我从交换机上插上网线，配好ip，然后运行

/etc/init.d/networking restart 然后，悲剧发生了，ssh断开然后连不上了，我赶快跑到服务器前，用ifup把两个网卡给启用了，然后正常了，我记得有的时候网卡是能自动起来的，但有时就不能，一个典型的网卡配置：

```bash
auto lo
iface lo inet loopback

allow-hotplug eth0
iface eth0 inet static
address 192.168.1.122
netmask 255.255.255.0
gateway 192.168.1.1
```

这是我在debian下的网络配置，但有时上面的allow-hotplug是被auto代替的，问题就在这里，allow-hotplug和auto的意义是不同的，allow-hotplug根据字面意思是“允许热插拔”，然后我经过查资料和实验终于弄明白了：

如果设置的是auto，不管你插不插网线，网卡都会启用，而且运行/etc/init.d/networking restart 之后网卡能自动起来

如果设置的是allow-hotplug，它会在开机时启动插网线的网卡，运行/etc/init.d/networking restart之后网卡不能自动重启

所以建议使用auto，但是如果设置网卡为dhcp，但是又没插网线，系统在启动，或者重启网络之后，系统会一直试图通过dhcp获取ip直到超时，这会影响系统的启动，最好是使用“auto”而且为每块网卡配置好ip
