hostapd

Pierwszym programem do postawienia serwera AP na Linux Debian może być hostapd, instalujemy paczkę

1
sudo apt-get install hostapd

i konfigurujemy plik /etc/hostapd/hostapd.conf

W nim można użyć takich wpisów:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
interface=wlo1
# interfejs wlo1 jest kartą sieciową na której odpalamy

logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2

ctrl_interface=/var/run/hostapd
ctrl_interface_group=0

ssid=TwojaSiec
# SSID czyli identyfikator sieci

country_code=PL
ieee80211d=1
hw_mode=g
channel=1
beacon_int=100
dtim_period=2
max_num_sta=255
rts_threshold=-1
fragm_threshold=-1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wmm_enabled=1
wmm_ac_bk_cwmin=4
wmm_ac_bk_cwmax=10
wmm_ac_bk_aifs=7
wmm_ac_bk_txop_limit=0
wmm_ac_bk_acm=0
wmm_ac_be_aifs=3
wmm_ac_be_cwmin=4
wmm_ac_be_cwmax=10
wmm_ac_be_txop_limit=0
wmm_ac_be_acm=0
wmm_ac_vi_aifs=2
wmm_ac_vi_cwmin=3
wmm_ac_vi_cwmax=4
wmm_ac_vi_txop_limit=94
wmm_ac_vi_acm=0
wmm_ac_vo_aifs=2
wmm_ac_vo_cwmin=2
wmm_ac_vo_cwmax=3
wmm_ac_vo_txop_limit=47
wmm_ac_vo_acm=0

ap_max_inactivity=300
ieee80211n=1
eapol_key_index_workaround=0
eap_server=0

own_ip_addr=192.168.2.1
wpa=2
wpa_passphrase=tajneHaslo
wpa_key_mgmt=WPA-PSK

wpa_pairwise=TKIP
rsn_pairwise=CCMP

Włącz konfigurację i start

edytuj plik /etc/default/hostapd

1
2
3
4
DAEMON_CONF="/etc/hostapd/hostapd.conf"
RUN_DAEMON="yes"
DAEMON_OPTS="-dd"
#ostatnia opcja do debugu

oraz załączamy przy starcie systemu

1
2
3
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd

Restartujemy system, teraz powinno pojawić się nowe WiFi, aby się połączyć prawidłowo trzeba by na sztywno ustawić adres IP taki, jak jest w sieci wlo1. Jednak lepiej postawić serwer DHCP.

DHCP serwer

1
sudo apt install isc-dhcp-server

edytujemy plik /etc/dhcp/dhcpd.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
option domain-name "t6.domena.com";
#adres domenowy komputera
option domain-name-servers 8.8.8.8, 8.8.4.4;

default-lease-time 600;
max-lease-time 7200;

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
#log-facility local7;

# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.

#subnet 10.152.187.0 netmask 255.255.255.0 {
#}

# This is a very basic subnet declaration.

#subnet 10.254.239.0 netmask 255.255.255.224 {
#  range 10.254.239.10 10.254.239.20;
#  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
#}
#subnet 10.254.239.0 netmask 255.255.255.224 {
#  range 10.254.239.10 10.254.239.20;
#  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
#}
subnet 192.168.2.0 netmask 255.255.255.0 {
  range 192.168.2.10 192.168.2.100;
  option routers 192.168.2.1;
  option broadcast-address 192.168.2.255;
}

Tabela routingu

1
route -n

Dążymy do tego by było coś w stylu

1
2
3
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 enp1s0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 enp1s0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 wlo1

Jeśli nie mamy takich wpisów, należy je dodać

1
2
sudo ip route add 192.168.2.0/24 dev wlo1
sudo ip route add 192.168.1.0/24 dev enpls0

„/24” oznacza podsieć 255.255.255.0

Musi też być przepychanie pakietów /etc/sysctl.conf

1
net.ipv4.ip_forward=1

i zapisz zmiany:

1
sudo sysctl -p

Na routerze bramy też trzeba ustawić odpowiedni routing do sieci 192.168.2.0. Teraz mamy poszerzoną sieć o drugą łączoną przez Wifi na AP Linux.