Connect to wifi via terminal

Hi. I need connect my router to wifi for install LuCi. On LuCi you can scan for select a near wifi and then you can install any packages for modify your router. But now I don't have LuCi cuz I installed a custumize bin file of OpenWrt. The documentation is confused for me (I don't speak english and I'm newbie), I've followed this official info but I think that is incomplete, I only see the wifi signals around me ( iw dev wlan0 scan) but I don't have any idea how to connect my principal wifi router.
How to connect to wifi via ssh?

Thank you in advance

https://openwrt.org/docs/guide-user/network/wifi/connect_client_wifi#setup_with_cli

OR
you could rebuild your custom bin with Luci included

Edit the /etc/config/wireless file to enable the radio (remove the option disabled line) and add a section like this:

config  wifi-iface
   option mode sta
   option device radio0
   option network wan
   option ssid 'my_network_name'
   option encryption psk2
   option key 'my_network_password'

Then edit /etc/config/network and remove any ifname (usually an ethernet port) from the wan section.

This should get it connected to the Internet unless the main router is also using 192.168.1.X addresses. In that case you need to change the lan IP address in /etc/config/network to 192.168.2.1 for example.

Hi @mk24, here my /etc/config/network:

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fd654:1c32:e3e1::/77'

config interface 'lan'
        option ifname 'eth0'
        option force_link '1'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

To the end I add?:

config  wifi-iface
   option mode sta
   option device radio0
   option network wan
   option ssid 'my_network_name'
   option encryption psk2
   option key 'my_network_password'

Oh sorry my mistake, the wifi configuration goes in /etc/config/wireless. I've edited my post.

In /etc/config/network, you need to delete the default Ethernet adapter to allow wifi to serve as your WAN connection instead. You do not need to specify the wifi interface there, placing option network wan in the wifi configuration is sufficient.

In a standard build there should be a wan interface and firewall zone pre-defined even if they aren't used (device with only one Ethernet port). If you don't already have it, add this to your /etc/config/network:

config interface wan
   option proto dhcp

Ok @mk24 , let's go. Here the info about my two config files with aggregated suggestions:

  • /etc/config/network:
config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.3'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fj41:3r42:f3g1::/475'

config interface 'lan'
        option ifname 'eth0'
        option force_link '1'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.3.1'
        option netmask '255.255.255.0'
        option ip6assign '70'

config interface 'wan'
        option proto 'dhcp'
  • /etc/config/wireless:
config wifi-device 'radio0'
        option type 'mac80211'
        option channel '11'   
        option hwmode '11g'
        option path 'platform/ar933x_wmac'
        option htmode 'HT20'              
        option disabled '0' 
                           
#config wifi-iface
        #option device 'radio0'
        #option network 'lan'  
        #option mode 'ap'    
        #option ssid 'OpenWrt'
        #option encryption 'none'
                                 
config wifi-iface
        option mode 'sta'
        option device 'radio0'
        option network 'wan'  
        option ssid 'router_name'
        option encryption 'psk2'
        option key 'router_password'

Result: NO wifi connection :frowning_face:

I could connect my router to wifi via ssh :smile: . I tell you how to do it. Thanks to @mk24 for the tips.

1. As the official info tells, go to inside your router vis ssh and follow the next previous steps:

uci set wireless.@wifi-device[0].disabled=0
uci commit wireless
wifi

2. Is necessary know some info about the wifi connection, so:

iw dev wlan0 scan

This commnad line shows important info like BSS id, router id and encryption protocol.

3. Now, edit the next config files: /etc/config/network and /etc/config/wireless (remember that OpenWrt include Vi editor, so for edit: vi /etc/config/network)

  • /etc/config/network

    Add the next lines to the end:

config interface 'wan'
        option proto 'dhcp'
  • /etc/config/wireless

    Change the uppercase words with your router info.

config wifi-device 'radio0'
        option type 'mac80211'
        option channel '11'
        option hwmode '11g'
        option path 'platform/ar933x_wmac'
        option htmode 'HT20'
        option disabled '0'
        option country 'US'

config wifi-iface
        option network 'wwan'
        option ssid 'ROUTER_ID'
        option encryption 'psk2'
        option device 'radio0'
        option mode 'sta'
        option bssid 'BSS_ID'
        option key 'PASSWORD'

4. Last step is reboot your router, at least in my case it's neccesary to do it for connect to wifi network.

1 Like

So it is working now?

The bssid is optional. That will force it to connect only to one particular AP in a situation where more than one AP having the same matching SSID is in radio range.

1 Like