Astaro useful shell commands.

Hi to All.
I'm opening this thread so any of you which happens to run into useful Shell commands, can add it in here.
My goal is to create a document with many Astaro useful shell commands.
You are welcome to add, remark or reject any of the commands in here.
[:)]



This thread was automatically locked due to age.
[unlocked by: BAlfson at 2:53 PM (GMT -7) on 4 Jun 2021]
  • Hi,
    anyone knows to reset the passwd of Admin on commandline?

    Firebear
  • To find a memory leak - essential.   Command line options I used to give 1 minute updates and sort on cache size: 

    slabtop -d 60 -s c

    Just watched TCP grab an extra 3 Meg of ram in 5 minutes taking the total to just shy of 800M ram for the TCP process. That is for 9.108.   Just rebooted ... now 11 Meg after 1 hour and 20 minutes.  

    Useful if you are swapping a lot and running out of RAM mysteriously.
  • Hello, 
    I think this set of instructions is what I need to do. If I am understanding correctly, you copy paste this code at the command line of UTM to convert eth0 to Vlan tagged after the switch port is set to trunk?

    # cc ↩
    set_object({class=>'interface', type=>'vlan', ref=>'REF_DefaultInternal', data=>{name=>'Internal', itfhw=>'REF_ItfHwDefaultInternal', primary_address=>'REF_ItfParamsDefaultInternal', bandwidth=>100000000, status=>1, vlantag=>1}}) ↩
    quit ↩

    That converts the untagged default internal interface eth0 to be a VLAN tagged interface eth0:1 (VLAN ID 1).

    Chad
  • Chad, 

    The example series of commands you're quoting will change REF_DefaultInternal, which is probably eth0, but as Mario mentioned, that's not guaranteed. Also, Mario's example is potentially changing more than just the VLAN settings, since you're rewriting the entire interface object. It will set all of the specified parameters, including the interface type and vlan ID. 

    Instead, assuming you know REF_DefaultInternal is the interface you want to change, just run this:
    cc change_object REF_DefaultInternal type=vlan vlantag=1

    The above single line command will change both the interface type, and the vlan tag in one command, but nothing else. If the command is successful, it will return the REF_id of the object you changed, or "0" on a failure.
    I don't know exactly when the change_object option was added, and may not work on older firmware versions, but it's a cleaner way to change just the parameters you mean to change. 

    -Alan
  • Thank you. I have my 2nd machine now set with ETH0 in vlan mode.
  • ethtool -p ethX 

    Forces a NIC to blink it's LEDs for identification purposes.

    Barry
  • See the traffic on one of your NIC :

    Specifying the local network(s) in the tcpdump command would limit the output to what you are looking for:

    sudo tcpdump -nn -p -i eth0 src or dst net 192.168.0.0/16

    assuming eth0 is external and all internal nets are in the 192.168.x.x space.
    the '-p' disables promiscuous mode, that is not needed for listening to your own traffic.

    (Thanks to Barry)
  • Enable local URL FIlter Database on Sophos UTM (Astaro ASG) 

    To set the database as local:

    cc set http sc_local_db [mem/disk/none]
    none     - default, don't use local categorization at all use online query as default.
    disk     - use local Database, but use it only on disk. Useful for boxes with little RAM.
    mem     - use local Database, and keep it in memory for faster access.


    Reload the service:
    /var/mdw/scripts/httpproxy restart


    Verify first DB download (Web surfing will be stopped until done - about 370 MB):
    ls -lh /var/chroot-http/var/pattern/sfcontrol


    Verify DB settings:
    cc get http sc_local_db
  • Clear Buffer Memory -( Useful for any linux):
    free -k; sync; echo 3 > /proc/sys/vm/drop_caches; free -k
    I’ve used this one in a pinch…not often tho.

    View the link speed for the ASG’s interfaces? 
    ‘ifstat’.

    Bandwidth usage – IFTOP
    Astaro also offers the command ‘iftop’ to see the live traffic and traffic statistics. 
    One can see the traffic live on an interface for Source Host, Destination Host, and Ports. 
    The peak and accumulative traffic is also displayed.
    Run ‘iftop’
    Example:
    root # iftop -i eth1

    Host display:————————–General:
    n – toggle DNS host resolution——P – pause display
    s – toggle show source host———h – toggle this help display
    d – toggle show destination host—–b – toggle bar graph display
    t – cycle line display mode———–B – cycle bar graph average
    ————————————— T – toggle cummulative line totals
    —————————————- Port display: j/k – scroll display
    N – toggle service resolution———f – edit filter code
    S – toggle show source port———-l – set screen filter
    D – toggle show destination port—–L – lin/log scales
    p – toggle port display—————- ! – shell command
    q – quit
    Sorting:
    1/2/3 – sort by 1st/2nd/3rd column
     – sort by dest name
    o – freeze current order

    Concurrent Connections:
    sysctl -w net.ipv4.netfilter.ip_conntrack_tcp_timeout_establ ished=86400

    number of established connections:
    less /proc/net/ip_conntrack | grep ESTA | wc -l
    1907

    number of all connections:
    less /proc/net/ip_conntrack | wc -l
    3315

    number of connections with status WAIT (close_wait):
    less /proc/net/ip_conntrack | grep WAIT | wc –l
    39

    Saving Snapshots of TOP automatically every half hour
    create a cron job with,
    top -b -n 1 >>/tmp/top-report.txt
    An entry for each CPU core, and possibly another if the CPU(s) has hyperthreading:
    cat /proc/cpuinfo

    stopped and started again the HTTP proxy:
    “/var/mdw/scripts/httpproxy stop” and “/var/mdw/scripts/httpproxy start”

    Restarting MiddleWare:
    service mdw restart
    (from root)
    Warning: it doesn’t cause a complete reboot, but it does cause an HA failover, interruption of any up/downloads and VoIP calls, etc. 

    HD
    Find what is taking the space type
    df –h
    df will only tell you how full the disk is.
    du will tell you what files/folders are using the most space
    I’d recommend:
    cd /var/storage
    du -sh *
    find the offending directories

    What kind of CPU
    “cat /proc/cpuinfo”?

    Determine if the disk is overloaded
    vmstat -d 5
    or
    vmstat -d | head -2 ; vmstat -d 5 | grep hda
    if hda is your hard disk; sda for scsi
    That should have similar output. 
    The ’5′ is 5 second updates.
    You’ll have to look at the differences between the lines to figure out how many IO’s you’re getting in those 5 seconds, and whether you’re saturating the disk or not.

    See detailed info about your eth:
    # ethtool eth1
    OR
    -mii-diag eth1

    webadmin passwd lost

    A user may use the following commands to reset the system passwords:
    cc
    RAW
    system_password_reset
    Ctrl c

    Upon saving the file and exiting, the admin may immediately navigate to WebAdmin and re-specify all passwords for the system accounts of Astaro Security Linux.

    DNS Flush cache option missing in V7
    the current workaround is to restart the DNS proxy from the command line as root with the following command:
    /var/mdw/scripts/named restart

    To change version number
    login as loginuser
    su -
    edit /etc/version
    save the file
    restart the ASG so the new version is displayed in Webadmin dashboard

    Change NIC order
    login as loginuser
    su -
    edit /etc/udev/rules.d/70-persistent-net.rules
    save the file
    restart the ASG so the new order is loaded.

    Locked out – How to regain all logins

    1) Shutdown the firewall and connect a screen and a keyboard to the firewall
    2) Power on the firewall, wait until the GRUB-loader starts and press ‘ESC’
    3) Select ‘Astaro Security Gateway 7.2’ (not previous or rescue!)
    4) Press ‘e’ to edit and select the 2nd entry
    5) Press ‘e’ once again and enter ‘init=/bin/bash’
    6) Press ‘ENTER’ and ‘b’ to boot up
    7) Now you are able to change the passwords for ‘loginuser’ and ‘root’
    8) After that press CTRL + ALT + DEL to reboot the system and wait until you get the login prompt

    Reset to factory settings
    Login the command-line as ‘loginuser’, afterwards as ‘root’ and enter following commands to restore to factory settings: 
    1. cc [Press ENTER]
    2. RAW [Press ENTER]
    3. system_factory_reset [Press ENTER]

    The system will automatically shutdown when it’s finished.nnels, becomes harder to read. Here’s a sample output:

    ‘REF_IpsSitFaketunnel’ => {
    0 => {
    0 => {
    ‘established’ => 0,
    ‘ike_auth’ => ‘psk’,
    ‘ike_lifetime’ => ’7800s’,
    ‘ike_natt’ => 0,
    ‘ipsec_lifetime’ => ’3600s’,
    ‘ipsec_sa’ => 0,
    ‘isakmp_sa’ => 0,
    ‘left’ => ’192.168.0.2′,
    ‘leftid’ => ’192.168.0.2′,
    ‘leftsubnet’ => ’192.168.25.0/24′,
    ‘right’ => ’10.0.0.1′,
    ‘rightid’ => ’10.0.0.1′,
    ‘rightsubnet’ => ’7.7.7.0/24′
    }
    },
    ‘all_established’ => 0,
    ‘established’ => 0,
    ‘expected’ => 1
    }
    }

    The bold items show you the status of each SA, and of the entire tunnel. 

    My absolute favorite command line tool is grep. Specifically, grep -oP can be used to pull specific data out of log lines, for summary. This requires being familiar with perl regex, but is extremely powerful. For example, how do you find out what errors have been seen most commonly in the web security log today?

    try this:
    grep -oP ‘error=”.*?”‘ /var/log/http.log

    That pulls a list of every error=”{anything}” instance out of the http log. Pipe this to some sorting commands, and we can get a nice sorted list of the most popular errors being returned by web servers:
    grep -oP ‘error=”.*?”‘ /var/log/http.log|sort -n|uniq -c|sort -n

    That will return something like this:
    1 error=”Connection refused”
    4 error=”DNS resolution timeout”
    5 error=”Host not found”
    23 error=”Connection timed out”
    48 error=”Timeout while reading response from Server”
    43703 error=”"

    This specific example can be helpful in identifying specific problems, like DNS problems. it also puts problems in perspective. 4 DNS timeouts out of 43k requests indicates that this probably isn’t a local problem. 

    The same commandscan be used in other ways, limited by your imagination (and regex knowledge). Be careful though, on extremely high volume systems, that may have problems from disk IO bottlenecks. searching like this will not help that situation improve TCP Parameter Changes

    Persistent change of ip conntrack timeout

    You can change them via command line.

    To see the current values:
    # cc get packetfilter timeouts
    packetfilter->timeouts = {
    “ip_conntrack_generic_timeout” => 600,
    “ip_conntrack_icmp_timeout” => 30,
    “ip_conntrack_tcp_timeout_close” => 10,
    “ip_conntrack_tcp_timeout_close_wait” => 60,
    “ip_conntrack_tcp_timeout_established” => 86400,
    “ip_conntrack_tcp_timeout_fin_wait” => 120,
    “ip_conntrack_tcp_timeout_last_ack” => 30,
    “ip_conntrack_tcp_timeout_max_retrans” => 300,
    “ip_conntrack_tcp_timeout_syn_recv” => 60,
    “ip_conntrack_tcp_timeout_syn_sent” => 120,
    “ip_conntrack_tcp_timeout_time_wait” => 120,
    “ip_conntrack_udp_timeout” => 30,
    “ip_conntrack_udp_timeout_stream” => 180
    }

    To increase a value, use:
    # cc set packetfilter timeouts ip_conntrack_udp_timeout 45

    Btw: There is udp_timeout and udp_timeout_stream.
    So if packets are send in both directions, then udp_timeout_stream is applied.

     

    To restore a backup from the command line, proceed as follows: 

    #Login using SSH:

    #:login: loginuser
    #[:P]assword: loginuser-password
    #Become root: #:su -
    #[:P]assword: root-password
    #Check the existing backup-files: #:backup.plx -l
    #Restore the backup file: #:backup.plx -n cfg_30916_1273834058 -i
    With ASG versions prior to 8.200, you had to type out the full path like this: :backup.plx -i /var/confd/var/storage/snapshots/cfg_30916_1273834058

    This still works with ASG 8.200 and higher, but is no longer necessary; the new “-n” option (mnemonic: read from Named backup) is much easier to use.

    (By Tony Schliesser)