Ubiquiti AirMax SSH Commands

ssh ubnt@192.168.1.20

AP:

list how many devices are connected.

wstalist |grep \"mac\" |wc -l
or
wstalist |grep -c \"mac\" 

List connected devices

wstalist

List ip’s of connected devices

wstalist |grep \"lastip\" | awk '{print $3}' | sed s/\"/\ /g | sed s/,//g

List connected devices with the device name and ip address of device

wstalist |grep -A1 \"name\" | sed s/\"/\ /g | sed s/,//g | grep -v "\--"

List connected devices along with device name, and signal.

wstalist |grep -A6 \"name\" | grep -E -v 'rx|tx|associd|aprepeater' | sed s/\"/\ /g | sed s/,//g | grep -v "\--"

 

Station:

Signal:

mca-status | grep signal

Signal, essid, frequency, noise, and ccq:

mca-status | grep -A4 essid

List basic info like device name, mac address, firmware version, platform, etc.

mca-status | head -n 1

Show Firmware Version:

mca-status | head -n 1 | awk -F, '{print $3}'

 

 

 

 

 

How To “Unblock” an IP from cPHulk from the Command Line

cPHulk uses a MySQL database to keep track of different IP’s to block, white list, black list, etc.

When there have been X amount of failed login attempts from an IP, cPHulk adds an entry for the IP in the brutes table.

To “unblock” the IP we need to delete the entry.

open up the cPHulk MySQL database.

root@localhost [~]# mysql cphulkd

If your interested you can view all tables that cPHulk uses.

show tables;

Take a look at all the IP’s in the brutes table.

SELECT IP FROM brutes;

example:

mysql> SELECT IP FROM brutes;
+---------------+
| IP            |
+---------------+
| 30.134.41.221 |     <--  IP we want to unblock
| 31.134.40.251 |
+---------------+
2 rows in set (0.00 sec)

mysql>

To unblock the IP we just need to delete the row that has the IP address we want.

mysql> DELETE FROM brutes WHERE IP="30.134.41.221";

It should return the following.

mysql> DELETE FROM brutes WHERE IP="30.134.41.221";
Query OK, 1 row affected (0.00 sec)

mysql>

Exit MySQL.

mysql> exit
Bye
root@localhost [~]#

 

How to set a static ip address on CentOS, Fedora, or Red Hat Linux

Open up the following file with your favorite text editor. Change eth0 to the interface you need, like “wlan0” or “eth1”.

 vi /etc/sysconfig/network-scripts/ifcfg-eth0

The file should look something like the following.

DEVICE=eth0
HWADDR=0A:2G:F3:56:66:4B
TYPE=Ethernet
UUID=aeh9421c-6a62-712c-886d-347813g8d1dh
ONBOOT=no
NM_CONTROLLED=yes
BOOTPROTO=dhcp

To set the static IP address change “BOOTPROTO=dhcp” to “BOOTPROTO=static” and add the following to the end of the file. If you want/need the interface to come up when the computer boots up then be sure to change “ONBOOT=no” to “ONBOOT=yes”.

BROADCAST=192.168.1.255
DNS1=8.8.8.8
GATEWAY=192.168.1.1
IPADDR=192.168.1.110
NETMASK=255.255.255.0

Also, on some newer versions of CentOS you may need to add NM_DISABLED=no

So your file should now look like this.

DEVICE=eth0
HWADDR=0A:2G:F3:56:66:4B
TYPE=Ethernet
UUID=aeh9421c-6a62-712c-886d-347813g8d1dh
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
BROADCAST=192.168.1.255
DNS1=8.8.8.8
GATEWAY=192.168.1.1
IPADDR=192.168.1.110
NETMASK=255.255.255.0

Save the file and restart networking.

service network restart

Finally, check you IP address with ifconfig.

root@localhost ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 0A:2G:F3:56:66:4B  
          inet addr:192.168.1.110  Bcast:192.168.1.255  Mask:255.255.255.0

Create an Image of a SD Card

The following command works on both OS X and Linux.  It creates an image from the SD card called raspi.img which you can later use to clone to another SD Card or just keep as a backup.  It is exceptionally useful for backing up a Raspberry Pi.

Replace “mmcblk0” with your SD cards name.  Take a look at this post if you need help finding the name.

sudo dd if=/dev/mmcblk0 of=~/raspi.img

How to Change, Add, and Delete Users in Linux

Changing a users name:

sudo usermod -l new-username old-username

To change the users directory name do the following.

 sudo usermod -d /home/new-username

You might need to log in as root or another user to successfully execute the commands.

Adding a user:

sudo useradd -m newuser

The -m option create the new users home directory

Then to activate the user we need to setup a password.

sudo passwd newuser

Enter and reenter the password and your done.

If you need to add the user to a certain group(s) (sudo?) you can do that with usermod

sudo usermod -G sudo,othergroups newuser

 

Deleting a user:

sudo userdel -r username

The “-r” option deletes the users mail and home directory.  If you wanted to keep them then just discard that option.

Finding a Drives Name in Linux From the Command Line

There are a few different ways to find out a drives(sdcard, usb drive, external hard drive) name.

dmesg command

One way to do it is to look at dmesg. Insert your drive and then run the command. It displays a lot of info, what we are interested in is the end which should say something about your drive.

dmesg
[ 4443.109976] mmc0: new high speed SDHC card at address aaaa
[ 4443.111857] mmcblk0: mmc0:aaaa SU04G 3.69 GiB 
[ 4443.120836]  mmcblk0: p1 p2
[ 4453.045338] EXT4-fs (mmcblk0p2): recovery complete
[ 4453.086165] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[ 4453.086184] SELinux: initialized (dev mmcblk0p2, type ext4), uses xattr

This tells us that the device is mmcblk0. The “p2” at the end is the partition number.

df Command

Another way to do it is to run the df command.
Run the below command without your drive plugged in.

df -h

it’ll return something like this

Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/fedora-root   50G   12G   36G  24% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G  600K  1.9G   1% /dev/shm
tmpfs                    1.9G  1.0M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
tmpfs                    1.9G   28K  1.9G   1% /tmp
/dev/sdb1                477M  115M  333M  26% /boot
/dev/mapper/fedora-home   76G   45G   23G  87% /home

The above command returns all the partitions that are mounted on your computer.
Now mount your drive and run the command again, it should show your drive at the bottom.

[me@fedora ~]$ df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/fedora-root   50G   12G   36G  24% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G  600K  1.9G   1% /dev/shm
tmpfs                    1.9G  1.1M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
tmpfs                    1.9G   28K  1.9G   1% /tmp
/dev/sdb1                477M  115M  333M  26% /boot
/dev/mapper/fedora-home   76G   45G   23G  87% /home
/dev/mmcblk0p2           3.6G  2.3G  1.1G  69% /run/media/me/fc522c75-9sws

You can see that the bottom one “/dev/mmcblk0p2 ” is the partition of the drive you just plugged in.

Using fdisk

You can also use fdisk.

sudo fdisk -l

It will return something similar to the following.

Disk /dev/mapper/fedora-home: 78.8 GiB, 191931351040 bytes, 374865920 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/mmcblk0: 3.7 GiB, 3965190144 bytes, 7744512 sectors

The bottom section is the drive “mmcblk0”.

Using lsblk

lsblk is another cool tool to list drives and partions. When run with the -p option it shows the path to the drive and partition.

Example output of what you may get with “lsblk -p”

admin@localhost:~$ lsblk -p
NAME                              MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
/dev/nvme1n1                      259:0    0   450G  0 disk  
├─/dev/nvme1n1p1                  259:1    0   499M  0 part  
├─/dev/nvme1n1p2                  259:2    0   100M  0 part  
├─/dev/nvme1n1p3                  259:3    0    16M  0 part  
└─/dev/nvme1n1p4                  259:4    0 449.3G  0 part  
/dev/nvme0n1                      259:5    0   477G  0 disk  
 ├─/dev/nvme0n1p1                  259:6    0   512M  0 part  /boot/efi
 ├─/dev/nvme0n1p2                  259:7    0   732M  0 part  /boot
 └─/dev/nvme0n1p3                  259:8    0   400G  0 part  
   └─/dev/mapper/vg-root           253:1    0   391G  0 lvm   /
   └─/dev/mapper/vg-swap_1         253:2    0   7.9G  0 lvm   [SWAP]
admin@localhost:~$ 

How to Install Flash on Linux

Installing flash on Ubuntu is pretty straight forward.  Type the following command into a terminal and press enter and away you go.

sudo apt-get install flashplugin-installer

On Fedora need to do the following

(64-bit)

sudo yum install http://linuxdownload.adobe.com/adobe-release/adobe-release-x86_64-1.0-1.noarch.rpm -y

(32-bit)

sudo yum install http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.noarch.rpm -y

And install the Adobe Flash web browser plugin.  The first command imports the GPG key for the Adobe Flash plugin repository and the second command installs the plugin itself.

sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux 
sudo yum install flash-plugin -y

How to Setup a Cron Job

There are a couple ways to set up a cron job.  If you have a script that you want to run ever so often, you could drop it in one of the cron directories, like cron.daily, or cron.weekly.  These are located in /etc.  Another way to do it is to use crontab.

To setup a cron job in crontab type

crontab -e

and then,

*/30 * * * * /path/to/yourscript.sh

The “*/30”  makes the script run every 30 minutes.  Below gives you a better idea of how the line works.  The asterisk (*) specifies all possible values for a field, but can/should be replaced with the time you want the script to execute.

* * * * * command to be executed

*(min) *(hr) *(DoM) *(month) *(week) /path/to/command_or_script.sh
  • min= Minute 0 – 50
  • hr = Hour 0-59
  • DoM = Day of month 0-31
  • month = Month 1-12
  • week = Day of Week 0-7, Sunday is 0 or 7

Below are a couple of examples of how to run a script or command.
Every minute.

* * * * * /path/to/script.sh

Every day 10 minutes after 1 in the morning,

10 1 * * * /path/to/command

Also, if you don’t want to be emailed the output of the command, you can simple append “>/dev/null 2>&1” to the end of the crontab line.
Example

0 * 1 * * /path/to/command/ >/dev/null 2>&1

How to set a Static IP Address in Ubuntu and Debian

The first thing we need to do, is open our interfaces file.  Execute the following from a terminal.

sudo vi /etc/network/interfaces

or

sudo nano /etc/network/interfaces

Then add or copy and paste the following.

auto eth0
iface eth0 inet static
        address 192.168.1.100
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1

Close the file. Now we need to change the DNS settings

sudo vi /etc/resolv.conf

or

sudo nano /etc/resolv.conf

Edit the nameserver line to something like the following.

nameserver 8.8.8.8

Close the file and then restart the networking stuff.

sudo /etc/init.d/networking restart

How to Open a Port on Redhat, CentOS or Fedora Linux

By default iptables firewall stores its configuration at /etc/sysconfig/iptables file. You need to edit this file and add rules to open port number.

Note: if you have SELinux  enabled, you’ll need to allow the port with semanage.

Open port 80

To open a different port just enter the port number.

Open flle /etc/sysconfig/iptables:

# vi /etc/sysconfig/iptables

Append rule as follows:

A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

Save and close the file.  Restart iptables:

# /etc/init.d/iptables restart

or,

#service iptables restart

 

Verify that port is open

Run the following command:

netstat -tulpn | less

Make sure iptables is allowing the port you enabled:

iptables -L -n

If you need more info you can refer to the man page:

man iptables