Linux: Difference between revisions
Jump to navigation
Jump to search
Line 119: | Line 119: | ||
===Add static route=== | ===Add static route=== | ||
<pre>ip route add 172.26.2.54 via 172.26.2.1 dev eth0</pre> | <pre>ip route add 172.26.2.54 via 172.26.2.1 dev eth0</pre> | ||
<b>Note</b> This clears on rebooting of the server | <b>Note:</b>This clears on rebooting of the server | ||
Create a file in /etc/sysconfig/network-scripts/route-eth0 with the below in the file: | Create a file in /etc/sysconfig/network-scripts/route-eth0 with the below in the file: |
Revision as of 15:11, 19 June 2019
Linux
Useful Commands
Show what is listening on what port
netstat -tulpn | grep LISTEN
Example output:
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 685/nrpe tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN 958/snmpd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 962/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1179/master tcp6 0 0 :::5666 :::* LISTEN 685/nrpe tcp6 129 0 :::2224 :::* LISTEN 663/ruby tcp6 0 0 :::22 :::* LISTEN 962/sshd tcp6 0 0 ::1:25 :::* LISTEN 1179/master
Show what version of Linux is running
cat /etc/*release
Example output:
CentOS Linux release 7.5.1804 (Core) NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7" CentOS Linux release 7.5.1804 (Core) CentOS Linux release 7.5.1804 (Core)
Show which directory is consuming how much space
du -h --max-depth=1
Example output:
13M ./src 268K ./.unison 20K ./.ssh 0 ./synctest 0 ./.pki 56M ./openssl-1.1.0f 4.0K ./.config 68M ./.cache 4.0K ./.local 104M ./vendor 262M .
Find a file
find / -name php.ini
Example output:
/etc/php.ini
Find in a file
grep -r "localhost" /etc/php.ini
Example output:
SMTP = localhost
Tar a file
tar -cvzf outputfile.tar.gz mysql-slow.log
Untar a file
tar -zxvf outputfile.tar.gz
List all pending updates to filename called servername
Centos/Redhat:
yum list updates > /tmp/"$(uname -n).txt"
Ubuntu:
apt-get upgrade --dry-run > /tmp/"$(uname -n).txt"
Example output of servername.txt:
Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.econdc.com * epel: mirrors.coreix.net * extras: anorien.csc.warwick.ac.uk * updates: mirror.sov.uk.goscomb.net Updated Packages GeoIP.x86_64 1.5.0-13.el7 base NetworkManager.x86_64 1:1.12.0-8.el7_6 updates NetworkManager-libnm.x86_64 1:1.12.0-8.el7_6 updates NetworkManager-ppp.x86_64 1:1.12.0-8.el7_6 updates NetworkManager-tui.x86_64 1:1.12.0-8.el7_6 updates NetworkManager-wifi.x86_64 1:1.12.0-8.el7_6 updates alsa-lib.x86_64 1.1.6-2.el7 base audit.x86_64 2.8.4-4.el7 base audit-libs.x86_64 2.8.4-4.el7 base bash.x86_64 4.2.46-31.el7 base bind-libs-lite.x86_64 32:9.9.4-73.el7_6 updates bind-license.noarch 32:9.9.4-73.el7_6 updates binutils.x86_64 2.27-34.base.el7 base centos-release.x86_64 7-6.1810.2.el7.centos base
Show journal
journalctl -xe
Add static route
ip route add 172.26.2.54 via 172.26.2.1 dev eth0
Note:This clears on rebooting of the server
Create a file in /etc/sysconfig/network-scripts/route-eth0 with the below in the file:
172.26.0.54 via 172.26.0.1 dev eth0
This will make the route survive a rebooting of the server.