Community discussions

MikroTik App
 
mktbm
just joined
Topic Author
Posts: 9
Joined: Tue Apr 09, 2024 11:46 pm

How to automatically connect to wireless network?

Fri May 17, 2024 1:10 am

I have a Mikrotik hAP ax2 which I mainly use for wireless access when travelling. My goal is to connect the router to the hotel wifi and act as an access point for all of my own devices. At this point I have the 2.4 GHz radio connected to the hotel wifi in station mode and I have created an access point using the 5 GHz radio.

My question is if it would be possible to create a list of known wifi networks (SSID & passphrase) which the router automatically connects to if any of the networks have been found to be accessible? If I am travelling between known locations (and networks) this would make it much easier to setup the router without the need to log in and reconfigure the station mode.

My configuration is as follows:
# 2024-05-17 00:00:20 by RouterOS 7.14.3
# software id = EX3R-84KS
#
# model = C52iG-5HaxD2HaxD
/interface bridge
add admin-mac=00:00:00:00:00:00 auto-mac=no name=bridge-LAN port-cost-mode=\
    short
/interface list
add comment=defconf name=WAN
add comment=defconf name=LAN
/interface wifi datapath
add bridge=bridge-LAN disabled=no name=datapath-LAN
add disabled=no interface-list=WAN name=datapath-WAN
/interface wifi
set [ find default-name=wifi1 ] channel.band=5ghz-ac .width=20/40mhz-Ce \
    configuration.mode=ap .ssid=wifi-AP datapath=\
    datapath-LAN disabled=no mtu=1500 name="wifi1A-AP (5GHz)" \
    security.authentication-types=wpa3-psk .wps=disable
/interface wifi configuration
add datapath=datapath-WAN disabled=no mode=station name=\
    network1 security.wps=disable ssid=network1
/interface wifi
set [ find default-name=wifi2 ] configuration=network1 \
    configuration.mode=station disabled=no name="wifi2A-CLIENT (2 GHz)"
/ip pool
add name=dhcp-pool-0 ranges=10.20.0.10-10.20.0.254
/ip dhcp-server
add address-pool=dhcp-pool-0 interface=bridge-LAN lease-time=1d name=\
    dhcp-server-0
/ip smb users
set [ find default=yes ] disabled=yes
/interface bridge port
add bridge=bridge-LAN interface=ether2
add bridge=bridge-LAN interface=ether3
add bridge=bridge-LAN interface=ether4
add bridge=bridge-LAN interface=ether5
/ip firewall connection tracking
set udp-timeout=10s
/ip neighbor discovery-settings
set discover-interface-list=LAN
/interface list member
add interface=ether1 list=WAN
add interface=bridge-LAN list=LAN
add interface=*B list=LAN
/ip address
add address=10.20.0.1/24 interface=bridge-LAN network=10.20.0.0
/ip cloud
set update-time=no
/ip dhcp-client
add interface=ether1
add interface="wifi2A-CLIENT (2 GHz)"
/ip dhcp-server network
add address=10.20.0.0/24 dns-server=10.20.0.1 gateway=10.20.0.1
/ip dns
set allow-remote-requests=yes
/ip firewall filter
add action=accept chain=input comment=\
    "defconf: accept established,related,untracked" connection-state=\
    established,related,untracked
add action=drop chain=input comment="defconf: drop invalid" connection-state=\
    invalid
add action=accept chain=input comment="defconf: accept ICMP" protocol=icmp
add action=accept chain=input comment=\
    "defconf: accept to local loopback (for CAPsMAN)" dst-address=127.0.0.1
add action=drop chain=input comment="defconf: drop all not coming from LAN" \
    in-interface-list=!LAN
add action=accept chain=forward comment="defconf: accept in ipsec policy" \
    ipsec-policy=in,ipsec
add action=accept chain=forward comment="defconf: accept out ipsec policy" \
    ipsec-policy=out,ipsec
add action=fasttrack-connection chain=forward comment="defconf: fasttrack" \
    connection-state=established,related hw-offload=yes
add action=accept chain=forward comment=\
    "defconf: accept established,related, untracked" connection-state=\
    established,related,untracked
add action=drop chain=forward comment="defconf: drop invalid" \
    connection-state=invalid
add action=drop chain=forward comment=\
    "defconf: drop all from WAN not DSTNATed" connection-nat-state=!dstnat \
    connection-state=new in-interface-list=WAN
/ip firewall nat
add action=masquerade chain=srcnat ipsec-policy=out,none out-interface-list=\
    WAN
/ip service
set telnet disabled=yes
set ftp disabled=yes
set ssh disabled=yes
set api disabled=yes
set api-ssl disabled=yes
/ip smb shares
set [ find default=yes ] directory=/pub
/ipv6 firewall address-list
add address=::/128 comment="defconf: unspecified address" list=bad_ipv6
add address=::1/128 comment="defconf: lo" list=bad_ipv6
add address=fec0::/10 comment="defconf: site-local" list=bad_ipv6
add address=::ffff:0.0.0.0/96 comment="defconf: ipv4-mapped" list=bad_ipv6
add address=::/96 comment="defconf: ipv4 compat" list=bad_ipv6
add address=100::/64 comment="defconf: discard only " list=bad_ipv6
add address=2001:db8::/32 comment="defconf: documentation" list=bad_ipv6
add address=2001:10::/28 comment="defconf: ORCHID" list=bad_ipv6
add address=3ffe::/16 comment="defconf: 6bone" list=bad_ipv6
/ipv6 firewall filter
add action=accept chain=input comment=\
    "defconf: accept established,related,untracked" connection-state=\
    established,related,untracked
add action=drop chain=input comment="defconf: drop invalid" connection-state=\
    invalid
add action=accept chain=input comment="defconf: accept ICMPv6" protocol=\
    icmpv6
add action=accept chain=input comment="defconf: accept UDP traceroute" port=\
    33434-33534 protocol=udp
add action=accept chain=input comment=\
    "defconf: accept DHCPv6-Client prefix delegation." dst-port=546 protocol=\
    udp src-address=fe80::/10
add action=accept chain=input comment="defconf: accept IKE" dst-port=500,4500 \
    protocol=udp
add action=accept chain=input comment="defconf: accept ipsec AH" protocol=\
    ipsec-ah
add action=accept chain=input comment="defconf: accept ipsec ESP" protocol=\
    ipsec-esp
add action=accept chain=input comment=\
    "defconf: accept all that matches ipsec policy" ipsec-policy=in,ipsec
add action=drop chain=input comment=\
    "defconf: drop everything else not coming from LAN" in-interface-list=\
    !LAN
add action=accept chain=forward comment=\
    "defconf: accept established,related,untracked" connection-state=\
    established,related,untracked
add action=drop chain=forward comment="defconf: drop invalid" \
    connection-state=invalid
add action=drop chain=forward comment=\
    "defconf: drop packets with bad src ipv6" src-address-list=bad_ipv6
add action=drop chain=forward comment=\
    "defconf: drop packets with bad dst ipv6" dst-address-list=bad_ipv6
add action=drop chain=forward comment="defconf: rfc4890 drop hop-limit=1" \
    hop-limit=equal:1 protocol=icmpv6
add action=accept chain=forward comment="defconf: accept ICMPv6" protocol=\
    icmpv6
add action=accept chain=forward comment="defconf: accept HIP" protocol=139
add action=accept chain=forward comment="defconf: accept IKE" dst-port=\
    500,4500 protocol=udp
add action=accept chain=forward comment="defconf: accept ipsec AH" protocol=\
    ipsec-ah
add action=accept chain=forward comment="defconf: accept ipsec ESP" protocol=\
    ipsec-esp
add action=accept chain=forward comment=\
    "defconf: accept all that matches ipsec policy" ipsec-policy=in,ipsec
add action=drop chain=forward comment=\
    "defconf: drop everything else not coming from LAN" in-interface-list=\
    !LAN
/system clock
set time-zone-name=Europe/Rome
/system identity
set name=RemoteRouter
/system note
set show-at-login=no
/system ntp client
set enabled=yes
/system ntp client servers
add address=pool.ntp.org
/tool mac-server
set allowed-interface-list=LAN
/tool mac-server mac-winbox
set allowed-interface-list=LAN