You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 22.04下以太网适配器与WiFi适配器的网桥搭建求助

Ubuntu 22.04下以太网适配器与WiFi适配器的网桥搭建求助

Hey there! I’ve been stuck trying to set up exactly this kind of bridge before, so let’s walk through this step by step to get your Ethernet and WiFi AP talking to each other—no DHCP, just static IPs, and no internet required.

Step 1: Find Your Network Interface Names

First, we need to know what your Ethernet and WiFi adapters are called. Run this command in the terminal:

ip link show

Look for lines like enp0s25 (that’s usually Ethernet) or wlan0 (WiFi). Jot these down—we’ll need them later.

Step 2: Install the Tools We Need

We’ll need two packages to build the bridge and set up the WiFi access point. Install them with:

sudo apt update && sudo apt install bridge-utils hostapd

Step 3: Stop NetworkManager (Temporarily, or Permanently)

NetworkManager might try to take over our interfaces and mess up the bridge. Let’s stop it first:

sudo systemctl stop NetworkManager
# Optional: Disable it so it doesn’t start back up on reboot
sudo systemctl disable NetworkManager

Step 4: Build the Network Bridge

Now we’ll create a bridge interface (br0) that connects both your Ethernet and WiFi adapters.

  1. First, turn off the existing interfaces to avoid conflicts:
# Replace $ETH with your Ethernet interface name (e.g., enp0s25)
sudo ip link set $ETH down
# Replace $WLAN with your WiFi interface name (e.g., wlan0)
sudo ip link set $WLAN down
  1. Create the bridge:
sudo brctl addbr br0
  1. Add both adapters to the bridge:
sudo brctl addif br0 $ETH $WLAN
  1. Turn off Spanning Tree Protocol (STP) since we’re dealing with a small, simple network—this avoids unnecessary delays:
sudo brctl stp br0 off
  1. Assign a static IP to the bridge. Pick a subnet that doesn’t overlap with any other networks you use (I’ll use 192.168.5.1/24 as an example):
sudo ip addr add 192.168.5.1/24 dev br0
  1. Bring everything back up:
sudo ip link set br0 up
sudo ip link set $ETH up
sudo ip link set $WLAN up

Step 5: Set Up the WiFi Access Point

Next, we’ll configure your WiFi adapter to act as an access point that connects to our bridge.

  1. Create a configuration file for hostapd (the tool that manages WiFi APs):
sudo nano /etc/hostapd/hostapd.conf
  1. Paste this into the file, replacing the placeholders with your own details:
interface=$WLAN  # Use your WiFi interface name here
bridge=br0  # This links the AP to our bridge
ssid=MyLocalNetwork  # Name your WiFi network whatever you want
hw_mode=g
channel=6
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=MyStrongPassword123  # Pick a secure password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Save and exit the editor (Ctrl+O, then Enter, then Ctrl+X).

  1. Tell hostapd where to find this config file:
sudo nano /etc/default/hostapd

Find the line that starts with #DAEMON_CONF="" and change it to:

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Save and exit again.

  1. Start and enable hostapd so it runs automatically on boot:
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd

Step 6: Configure Static IPs for All Devices

Since we’re not using a DHCP server, you’ll need to manually set static IPs for every device connected to either the Ethernet or WiFi AP. Make sure each device uses an IP in the same subnet as the bridge (like 192.168.5.2 to 192.168.5.254) and uses the bridge’s IP (192.168.5.1) as its gateway (if needed for devices to talk to each other).

Step 7: Check If It’s Working

  • Run brctl show br0 to confirm both your Ethernet and WiFi adapters are listed under the bridge.
  • Connect a device to your new WiFi AP, then ping a device on the Ethernet network (and vice versa) to make sure they can communicate.

Quick Troubleshooting

  • If the WiFi AP doesn’t show up: Double-check the hostapd config file for typos, especially the interface name and password.
  • If devices can’t ping each other: Make sure their static IPs are in the same subnet, and check if your firewall (ufw) is blocking traffic. You can allow traffic through the bridge with:
sudo ufw allow in on br0 && sudo ufw allow out on br0

备注:内容来源于stack exchange,提问作者AGC79

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 08:24:29