Ubuntu 17.10多网卡静态IP配置(Netplan方式)
Hey there! Let's get your eth1 interface set up with a static IP on the 192.168.20.0/24 subnet in Ubuntu 17.10 using Netplan. Since you already have your 01-netcfg.yaml working for eth0, this should be a smooth addition—just remember Netplan uses YAML, which is super picky about indentation (stick with spaces, no tabs!).
Step 1: Edit your existing Netplan config file
Open up your working config with a text editor (I prefer nano for simplicity):
sudo nano /etc/netplan/01-netcfg.yaml
Step 2: Add the eth1 configuration
Below your eth0 settings, add the block for eth1. Here’s a complete example assuming your eth0 is on a different subnet (like 192.168.10.0/24) with a default gateway—note that we don’t set a default gateway for eth1 unless you specifically need it (you can only have one default gateway per system):
network: version: 2 renderer: networkd ethernets: eth0: addresses: - 192.168.10.10/24 gateway4: 192.168.10.1 nameservers: addresses: [8.8.8.8, 8.8.4.4] eth1: addresses: - 192.168.20.10/24 # Uncomment the line below if eth1 needs its own gateway (not default!) # gateway4: 192.168.20.1 # Optional: Set custom DNS servers for eth1 # nameservers: # addresses: [192.168.20.1]
Step 3: Validate the config syntax
Before applying, check for YAML errors (this will save you headaches later):
sudo netplan generate
If you get no output, the syntax is good. If there’s an error, it’ll tell you where to fix it (usually indentation issues).
Step 4: Apply the new configuration
Make the changes live without rebooting:
sudo netplan apply
Step 5: Verify everything works
Check that eth1 has the correct static IP:
ip addr show eth1
You should see 192.168.20.10/24 listed under the interface. To check routing (if you set a gateway for eth1):
ip route
Quick Notes
- Indentation is critical: YAML requires consistent spacing (2 spaces per level is standard). Mixing tabs and spaces will break the config.
- Static routes (if needed): If
eth1needs to reach another subnet (like 192.168.30.0/24), add aroutesblock toeth1:eth1: addresses: - 192.168.20.10/24 routes: - to: 192.168.30.0/24 via: 192.168.20.1 - Renderer choice: If you’re using a desktop environment instead of a server, you might need to set
renderer: NetworkManagerinstead ofnetworkd, but server editions default tonetworkdwhich is what you want here.
内容的提问来源于stack exchange,提问作者Josho

