Linux 设置双网卡通信,外网网卡和内网网卡
时间: 2024-09-19 12:05:48 浏览: 90
在Linux系统中设置双网卡通信,通常需要配置网络接口文件`/etc/network/interfaces`或其对应版本(如在Ubuntu中是`/etc/netplan/*.yaml`)。首先,你需要确定两个网卡的名称,例如eth0代表外网卡,eth1代表内网卡。
以下是基本步骤:
1. **查看网络设备**:
打开终端,运行 `ifconfig` 或 `ip addr` 来查看所有可用的网络接口及其状态。
2. **编辑配置文件**:
使用文本编辑器打开网络配置文件。如果是`interfaces`文件,添加类似这样的内容:
```bash
auto eth0
iface eth0 inet dhcp # 配置外网卡获取动态IP
auto eth1
iface eth1 inet static
address <内网IP>
netmask <子网掩码>
gateway <默认网关> # 内网网关
```
如果用`netplan`,则创建一个新的配置文件或修改现有文件,加入类似于:
```yaml
network:
version: 2
interfaces:
eth0:
dhcp4: yes
eth1:
inet4:
address: <内网IP>
netmask: <子网掩码>
gateway4: <内网网关>
```
3. **启用并重启网络服务**:
保存配置后,更新网络配置并重启网络服务:
```
sudo nano /etc/network/interfaces (或其他编辑器)
sudo netplan apply
sudo service networking restart
```
4. **检查连接**:
确认两块网卡已经正确配置,你可以分别ping内外网地址测试是否能正常通信。
阅读全文
相关推荐

















