Post

Configuring OpenWrt via Command Line

I’ll be sharing my personal experience on how to configure OpenWrt via command line for TMnet ISP. With just a few simple commands, you can easily set up your router to work with your ISP and get your network up and running in no time.

When configuring OpenWrt via command line for TMnet ISP, I prefer to use Windows PowerShell (Win + X » Windows Powershell). Here are the steps I follow:

SSH into OpenWrt Router

1
2
rm -r  "~\.ssh"
ssh root@192.168.1.1

Next time I can simply use ssh root@192.168.1.1

How to tell: DSA vs Swconfig

To determine if my router uses DSA or Swconfig, I use the following commands:

DSA (eg: Mi Router 4A, D-Link DIR-882, Linksys E8450)

1
2
swconfig list
-ash: swconfig: not found

Swconfig (eg: Tp-Link Archer C7, D-Link DIR-842)

1
2
swconfig list
Found: switch0 - mdio.0

If my router uses Swconfig, I follow this guide instead.

Set up UniFi PPPoE Username & Password

To set up my UniFi PPPoE username and password, I use the following commands:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
PPPOE_USERNAME=xxxx@unifi
PPPOE_PASSWORD=xxxxxxxxxxxxxx
DNS_1=1.1.1.1
DNS_2=8.8.8.8
DNS6_1=2606:4700:4700::1111
DNS6_2=2001:4860:4860::8888
uci set network.wan.proto='pppoe'
uci set network.wan.username=$PPPOE_USERNAME
uci set network.wan.password=$PPPOE_PASSWORD
uci set network.wan.device='wan.500'
uci set network.wan.ipv6='1'
uci set network.wan.peerdns='0'
uci set network.wan.dns="$DNS_1 $DNS_2"
uci set network.wan6.proto='dhcpv6'
uci set network.wan6.device='@wan'
uci set network.wan6.peerdns='0'
uci set network.wan6.dns="$DNS6_1 $DNS6_2"
uci commit network
ifup wan
echo 'Waiting for link to initialize'
sleep 20

Extras

Set Router Passsword

To set a new root password for my router, I use the following command:

1
2
3
4
5
6
echo 'Updating root password'
NEWPASSWD=123
passwd <<EOF
$NEWPASSWD
$NEWPASSWD
EOF

Set Correct Timezone

To set the correct timezone, I use the following commands:

1
2
3
4
5
6
7
8
TIMEZONE='<+08>-8'
ZONENAME='Asia/Kuala Lumpur'
echo 'Setting timezone to' $TIMEZONE
uci set system.@system[0].timezone="$TIMEZONE"
echo 'Setting zone name to' $ZONENAME 
uci set system.@system[0].zonename="$ZONENAME"
uci commit system
/etc/init.d/system reload

Set Router Hostname

To set the router hostname, I use the following commands:

1
2
3
4
5
HOSTNAME="LiNKSYS"
uci set system.@system[0].hostname=$HOSTNAME
uci set network.lan.hostname="`uci get system.@system[0].hostname`"
uci commit system
/etc/init.d/system reload

Install Optional Packages

1
2
3
4
5
opkg update                # retrieve updated packages
opkg install luci-app-sqm  # install the SQM modules to get fq_codel etc
opkg remove wpad-basic-wolfssl  # remove the non-mesh version of wpad
opkg install wpad-mesh-wolfssl  # Install the mesh supporting version
opkg intall luci-app-attendedsysupgrade # Install Attended Sysupgrade for keeping firmware up-to-date

With these commands, you can easily set up your router and get your network up and running. And the best part? You did it all from the command line, which can be a powerful tool for networking professionals. I hope this guide has been helpful to you. If you have any questions or feedback, feel free to leave a comment below.

Research

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.