linux network command line

ifconfig, show all network interfaces

Ex.

root@kali:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.160.128 netmask 255.255.255.0 broadcast 192.168.160.255
inet6 fe80::20c:29ff:feae:2778 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:ae:27:78 txqueuelen 1000 (Ethernet)
RX packets 53526 bytes 79273540 (75.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 18397 bytes 1117190 (1.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 97 bytes 7040 (6.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 97 bytes 7040 (6.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wlan0: flags=4099<UP,BROADCAST,MULTICAST> mtu 2312
ether ba:d7:b2:b4:4d:a8 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

iwconfig, show only all wireless network interfaces

Ex.

root@kali:~# iwconfig

lo        no wireless extensions.

eth0      no wireless extensions.

wlan0     unassociated  Nickname:”<WIFI@REALTEK>”

          Mode:Auto  Frequency=2.412 GHz  Access Point: Not-Associated   

          Sensitivity:0/0  

          Retry:off   RTS thr:off   Fragment thr:off

          Encryption key:off

          Power Management:off

          Link Quality=0/100  Signal level=0 dBm  Noise level=0 dBm

          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0

          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

The most interesting thing of iwconfig command is the Mode.

 

Java application as Linux Service in 4 steps

If you are reading this post then, probably, you need to execute your java app as a Linux service.

This can be done in 4 really easy steps

  • Create the service
  • create a bash script
  • give execution permission to the bash file
  • enable and start your brand new service

Step 1: create the system service

sudo nano /etc/systemd/system/MyFantasticJavaApp.service

it will open the nano editor. Add the following, changing the working directory and the User values based on your convenience

                                                                                                 
 [Unit]
 Description=good old Java application
 [Service]
 User=root  
 # The configuration file application.properties should be here:
 # change this with your workspace
 WorkingDirectory=/usr/local/javaproject/

 #path to executable.
 #executable is a bash script which calls jar file
 ExecStart=/usr/local/javaproject/myBashFile
 SuccessExitStatus=143
 TimeoutStopSec=10
 Restart=on-failure
 RestartSec=5
 [Install]
 WantedBy=multi-user.target

save the file (Ctrl-X, select Y(es) and press enter)

Step 2: create the bash script

Now let’s create a script which will basically call our jar/war file.

This file has to be the one specified in previous service file (what we call in ExecStart value). So, let’s write:

sudo nano /usr/local/javaproject/myBashFile

it will open (again) the nano editor. Add the following 2(two) lines, changing the port and the path to your jar/war file

#!/bin/sh
 sudo /usr/bin/java -Dserver.port=7080  -jar /usr/local/javaproject/MyFantasticJavaApp.jar

save the file (Ctrl-X, select Y(es) and press enter)

Step 3: give execution permission to the basch script

this is the simpler step. Just write this, changing the file and his path:

sudo chmod u+x /usr/local/javaproject/myBashFile

Step 4, almost there: let’s play the new service

sudo systemctl daemon-reload
sudo systemctl enable MyFantasticJavaApp.service
sudo systemctl start MyFantasticJavaApp

Et voila! Do not thank me!