Skip to content

Commit

Permalink
Config option: specify ethernet interface
Browse files Browse the repository at this point in the history
Added optional config setting to allow people to specify ethernet interface. Defaults to eth0.
  • Loading branch information
mattlongman committed Apr 23, 2023
1 parent 5db13bd commit 36536f3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Please add
- **netmask** (**required**): Subnet mask of the network
- **broadcast** (**required**): Broadcast address of the network
- **interface** (_optional_): Which wlan card to use. Default: wlan0
- **eth_interface** (_optional_): Which ethernet interface to use. Default: eth0
- **hide_ssid** (_optional_): Whether SSID is visible or hidden. 0 = visible, 1 = hidden. Defaults to visible
- **dhcp** (_optional_): Enable or disable DHCP server. 0 = disable, 1 = enable. Defaults to disabled
- **dhcp_start_addr** (_optional_): Start address for DHCP range. Required if DHCP enabled
Expand Down
5 changes: 5 additions & 0 deletions hassio-access-point/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
- Error: "wlan0: Could not connect to kernel driver" - https://raspberrypi.stackexchange.com/a/88297
- **If anyone has any knowledge relating to the underlying modules, or just wants to assist with testing this addon, please get in touch, submit PRs, etc.**

## [0.4.5] - 2023-04-23

### Added
- Optional config option to specify ethernet interface. Defaults to eth0.

## [0.4.4] - 2022-12-20

### Fixed
Expand Down
4 changes: 3 additions & 1 deletion hassio-access-point/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Hass.io Access Point",
"version": "0.4.4",
"version": "0.4.5",
"slug": "hassio-access-point",
"description": "Create a WiFi access point to directly connect devices to Home Assistant",
"arch": ["armhf", "armv7", "aarch64", "amd64", "i386"],
Expand All @@ -22,6 +22,7 @@
"netmask": "255.255.255.0",
"broadcast": "192.168.99.255",
"interface": "wlan0",
"eth_interface": "eth0",
"hide_ssid": "0",
"dhcp": "0",
"dhcp_start_addr": "192.168.99.10",
Expand All @@ -42,6 +43,7 @@
"netmask": "str",
"broadcast": "str",
"interface": "str",
"eth_interface": "str",
"hide_ssid": "int",
"dhcp": "int",
"dhcp_start_addr": "str",
Expand Down
10 changes: 8 additions & 2 deletions hassio-access-point/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ADDRESS=$(jq --raw-output ".address" $CONFIG_PATH)
NETMASK=$(jq --raw-output ".netmask" $CONFIG_PATH)
BROADCAST=$(jq --raw-output ".broadcast" $CONFIG_PATH)
INTERFACE=$(jq --raw-output ".interface" $CONFIG_PATH)
ETH_INTERFACE=$(jq --raw-output ".eth_interface" $CONFIG_PATH)
HIDE_SSID=$(jq --raw-output ".hide_ssid" $CONFIG_PATH)
DHCP=$(jq --raw-output ".dhcp" $CONFIG_PATH)
DHCP_START_ADDR=$(jq --raw-output ".dhcp_start_addr" $CONFIG_PATH)
Expand All @@ -45,6 +46,11 @@ if [ ${#INTERFACE} -eq 0 ]; then
INTERFACE="wlan0"
fi

# Set eth_interface as eth0 if not specified in config
if [ ${#ETH_INTERFACE} -eq 0 ]; then
INTERFACE="eth0"
fi

# Set debug as 0 if not specified in config
if [ ${#DEBUG} -eq 0 ]; then
DEBUG=0
Expand Down Expand Up @@ -214,7 +220,7 @@ if [ $DHCP -eq 1 ]; then
if [ $CLIENT_INTERNET_ACCESS -eq 1 ]; then

## Route traffic
iptables-nft -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables-nft -t nat -A POSTROUTING -o $ETH_INTERFACE -j MASQUERADE
iptables-nft -P FORWARD ACCEPT
iptables-nft -F FORWARD
fi
Expand All @@ -224,7 +230,7 @@ else
## No DHCP == No DNS. Must be set manually on client.
## Step 1: Routing
if [ $CLIENT_INTERNET_ACCESS -eq 1 ]; then
iptables-nft -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables-nft -t nat -A POSTROUTING -o $ETH_INTERFACE -j MASQUERADE
iptables-nft -P FORWARD ACCEPT
iptables-nft -F FORWARD
fi
Expand Down

0 comments on commit 36536f3

Please sign in to comment.