Pages

Monday, October 2, 2023

Useful Linux Troubleshoot commands

Check for duplicate IPs

arping -I eth1 20.20.187.194

ARPING 20.20.187.194

60 bytes from 00:50:56:a8:92:fa (20.20.187.194): index=0 time=487.776 usec

60 bytes from 00:50:56:9b:02:3a (20.20.187.194): index=1 time=718.761 usec=

    -i interface

           Use the specified interface.

reply is from 2 different mac address


How to disable SSH timeout?

To set the SSH keep alive option on the server:

1. Log in as root.

2. Edit the file at /etc/ssh/sshd_config.

3. Add this line to the file: ClientAliveInterval 60.

4. Save the file.

5. Restart sshd on the server.

Or 

ssh -o ServerAliveInterval=0 root@10.90.137.118


To check how many ssh sessions are connected to device

netstat -tunp | grep 22

(Not all processes could be identified, non-owned process info

will not be shown, you would have to be root to see it all.)

tcp 0 256 10.10.5.9a:22 10.65.92.231:62650 ESTABLISHED 11532/0 

tcp 0 0 127.0.0.1:42294 127.0.0.1:5759 ESTABLISHED - 

tcp 0 0 127.0.0.1:5759 127.0.0.1:42294 ESTABLISHED -


How to check available space on machine?

root@systest-runner:~[38200]# free -mh 

              total        used        free      shared  buff/cache   available

Mem:          16038       15473         191           5         373         240


How to increase ssh timeout in Linux?

https://www.tecmint.com/increase-ssh-connection-timeout/


Disk space used by directories.

du -sh * | grep G


check which are top 5 storage occupying folders/files

du -hs * | sort -rh | head -5


Delete files older than 90 days

find . -mtime +$90 -type f -delete


To check size of directory:

du -h <dir>


Copy multiple files using scp

scp -r root@<ip>:/root/edges .


Check image is copied properly in tftp:

[root@iLnxRTR3 dbuild_02072015]# ls

cdisk.smp  checksum 

[root@iLnxRTR3 dbuild_02072015]# md5sum cdisk.smp 

b9f2913fca176d4fbcc7a9dbc0673aaf  cdisk.smp

[root@iLnxRTR3 dbuild_02072015]# cat checksum 

b9f2913fca176d4fbcc7a9dbc0673aaf  target/smp/cdisk.smp

[root@iLnxRTR3 dbuild_02072015]#


Create alias on terminal

vi ~/.bashrc

alias 1='telnet <ip> <port>'

For ssh alias:

alias n1="sshpass -p VMware1VMware! ssh root@<ip>"                        

source ~/.bashrc


Configure dns on Ubuntu

https://www.fosslinux.com/7631/how-to-install-and-configure-dns-on-ubuntu.htm

https://serverfault.com/questions/300438/bind9-failing-to-start


Enable tftp server: 

https://graspingtech.com/ubuntu-tftp-server/


To find username of windows machine:

> echo %usermae%


Curl commands:

GET (-v for verbose) without any option by default is GET 

curl -v http://localhost:8082/spring-rest/foos/9 


POST (-d data, -H to modify content type ) 

curl -d '{"id":9,"name":"baeldung"}' -H 'Content-Type: application/json' http://localhost:8082/spring-rest/foos/new 


PUT: (-x for put)

curl -d @request.json -H 'Content-Type: application/json' 

-X PUT http://localhost:8082/spring-rest/foos/9 


DELETE (-X for delete) 

curl -X DELETE http://localhost:8082/spring-rest/foos/9 


Authentication 

curl --user baeldung:secretPassword http://example.com/ 


How to check DNS configuration on MAC:

NAWLEKHA-M-N1AJ:~ nawlekha$ scutil --dns

DNS configuration

resolver #1

  nameserver[0] : 192.168.1.254

  if_index : 5 (en0)

  flags    : Request A records

  reach    : 0x00020002 (Reachable,Directly Reachable Address)


How to flush dns in mac?

nawlekha$ sudo killall -INFO mDNSResponder


For cmake error - cmake: command not found

=========

sudo apt-get install build-essential cmake


Resolve Ipv6 ping issue : 

https://askubuntu.com/questions/64500a/ipv6-connect-network-is-unreachable


Error: You don't have enough free space in /var/cache/apt/archives/' errors

============

https://www.marksayson.com/blog/investigating-space-issues-in-var-cache-apt-archives/

delete files from /var directory


To disable auto ipv6 on Linux:

=====================

sudo sysctl -w net.ipv6.conf.all.forwarding=1

ifconfig eth0.912 down

ifconfig eth0.912 up


Error: update stuck at : 0% [Connecting to us.archive.ubuntu.com (2001:67c:1562::15)]

============

It's better to disable the IPV6 before you update ## check this in below link 

https://askubuntu.com/questions/574569/apt-get-stuck-at-0-connecting-to-us-archive-ubuntu-com


Error: If you are able to configure ipv6 address and seeing below error:

root@Ubuntu-Linux-2:~/sipp# ifconfig ens224.1670 inet6 add 172:52:1::2/64

SIOCSIFADDR: Permission denied

root@Ubuntu-Linux-2:~/sipp# /sbin/route -A inet6 add default gw 172:52:1::1

SIOCADDRT: No route to host

Follow same above link and enable ipv6

https://askubuntu.com/questions/574569/apt-get-stuck-at-0-connecting-to-us-archive-ubuntu-com


Create a Static ARP Table

If you know that the MAC address that corresponds to 192.16a.0.65 is 00:50:BA:a5:a5:CA, you could add a static ARP entry for it like this:

# arp -s 192.16a.0.65 00:50:ba:a5:a5:ca ## destination ip and corresponding mac


flush arp:

ip -s -s neigh flush all


delete arp for particular ip

arp -d 192.168.1.1


to check arp table

arp -n


To ping from specific interface;

ping -I ens33 9.9.9.8


Issue: Ubuntu is always taking ipv6 DNS server to reach internet and its not resolving.

root@tls-client:~# ping google.com

PING google.com(maa05s02-in-x0e.1e100.net (2404:6a00:4007:a0c::200e)) 56 data bytes

From 50:5:5::1 (50:5:5::1) icmp_seq=1 Destination unreachable: No route

From 50:5:5::1 (50:5:5::1) icmp_seq=2 Destination unreachable: No route

From 50:5:5::1 (50:5:5::1) icmp_seq=3 Destination unreachable: No route

https://askubuntu.com/questions/3229a/prefer-a-ipv4-dns-lookups-before-aaaaipv6-lookups


How to re-write pcap:

sudo tcprewrite -C -i input.cap -o output.cap

https://tcpreplay.appneta.com/wiki/tcprewrite


## how to create root user in Ubuntu

user@Ubuntu-Linux-1:~$ sudo su

[sudo] password for user: 

root@Ubuntu-Linux-1:/home/user# passwd

Enter new UNIX password: 

Retype new UNIX password: 

passwd: password updated successfully


Proxy settings:

export https_proxy="https://proxy-wsa.esl.domain.com:80"


To copy everything present under directory:

cp -rf * /ws/nawlekha-bgl/automation/pyats/automation_package_bangalore_mc/.


How to copy using ftp from windows VM to mac

ftp user@10.104.10.113

ftp> ha

Hash mark printing on (1024 bytes/hash mark).

ftp> bi

200 Type set to I

ftp> 

ftp> ls

ftp> get KP_RA_IPSEC_ASA.p12

ftp> bye


How to connect to website through port  using ipv4 and ipv6?

http://1a0.1.1.10:90

http://[2001:dba:90::2]:90/


GET OS name

root@Ubuntu-Linux-1:~# cat /etc/os-release

NAME="Ubuntu"


How to restart dns service

[root@olinux1 named]# /etc/init.d/named restart


Convert ipv4 to ipv6 address:

3.3.5.245

in browser type [::3.3.5.245]

it will return ::303:5f5. use this address


Disable ipv6 autoconfig on Ubuntu

To check if IPv6 is enabled or disabled, from a terminal window:

$ cat /proc/sys/net/ipv6/conf/all/disable_ipv6

0 means it’s enabled and 1 is disabled.


Network settings in Ubuntu:

sudo vi /etc/network/interfaces


How to convert ipv4 to ipv6

convert ipv4 to ipv6 

60.1.1.10/24 to 60:1:1::10/96


Linux commands in DevOps: Must Know For Every DevOps Professional

https://www.edureka.co/blog/linux-commands-in-devops/


To check packet loss

ping 10.90.137.64 -c5

PING 10.90.137.64 (10.90.137.64): 56 data bytes

64 bytes from 10.90.137.64: icmp_seq=0 ttl=55 time=16.201 ms

Request timeout for icmp_seq 1

64 bytes from 10.90.137.64: icmp_seq=2 ttl=55 time=22.651 ms

Request timeout for icmp_seq 3

64 bytes from 10.90.137.64: icmp_seq=4 ttl=55 time=16.290 ms

--- 10.90.137.64 ping statistics ---

5 packets transmitted, 3 packets received, 40.0% packet loss

round-trip min/avg/max/stddev = 16.201/18.381/22.651/3.020 ms


## udpreplay is a lightweight alternative to tcpreplay for replaying UDP unicast and multicast streams from a pcap file


List IP tables

iptables --table nat --list


No comments:

Post a Comment