Showing posts with label Linux for Networking. Show all posts
Showing posts with label Linux for Networking. Show all posts

Thursday 24 October 2019

Awesome Tcpdump Hack for Arista EOS to send to Wireshark

These below commands allow anyone to live stream the packet info to wireshark application on their Mac without having to capture on their device and then copy to mac...


To send tcpdump directly to wireshark:
ssh root@mt701 "tcpdump -s 0 -Un -w - -i vlan100" | wireshark -k -i -

The above command will:
- Tcpdump on the Arista EOS device mt701
- Capture packets of vlan100 (change to your desired interface)
- Pipe the output to Wireshark application on your Mac/Desktop


Tcpdump on a different VRF-"dhcpvrf"
ssh root@mc327 "ip netns exec ns-dhcpvrf tcpdump -i vlan10 port 67 or port 68 " | wireshark -k -i -

The main command telling the VRF info is: "ip netns exec ns-dhcpvrf tcpdump -i vlan2 port 67 or port 68"

The above command will:
- Tcpdump on the Arista EOS device mc327
- Capture packets on VRF "dhcpvrf" (change name to your desired vrf name)
- Capture packets of vlan2 (change to your desired interface)
- Capture packets on Port 67 or Port 68 only
- Pipe the output to Wireshark application on your Mac/Desktop

Wednesday 1 August 2018

Linux Networking Utilities for Arista EOS- Part 2

Linux Networking Utilities for Arista EOS 

LINUX NETWORKING UTILITIES:

.

ip netns: (Linux Namespaces or VRF)

  • A network namespace is logically another copy of the network stack, with its own routes, firewall rules, and network devices.
  • By default a process inherits its network namespace from its parent. Initially all the processes share the same default network namespace from the init process.
  • NOTE: If a VRF was created in EOS, then, in order to access then via Linux; append ‘ns-’ to the VRF name.
  • NOTE: If a namespace was created in Linux, then, it won’t show up in EOS.
  • So, always create a VRF in EOS and use it in Linux by appending ‘ns-’ to the VRF name
  • 1. ip netns list - show all of the named network namespaces
  • This command displays all of the network namespaces in /var/run/netns
  • Note that the VRF named ‘tmod’ when viewed in Linux has the name ‘ns-tmod’

[admin@ck338 ~]$ ip netns list

ns-newvrf

ns-tmod

ns-trident

ns-arad

default

  • 2. ip netns add NAME - create a new named network namespace
  • If NAME is available in /var/run/netns/ this command creates a new network namespace and assigns NAME.

[admin@ck338 ~]$ sudo ip netns add testvrf

[admin@ck338 ~]$ ip netns list

testvrf

ns-newvrf

ns-tmod

ns-trident

ns-arad

default

  • 3. ip [-all] netns delete [ NAME ] - delete the name of a network namespace(s)
  • If NAME is present in /var/run/netns it is umounted and the mount point is removed.
  • If -all option was specified then all the network namespace names will be removed.

[admin@ck338 ~]$ sudo ip netns delete testvrf

  • 4. Assigning Interfaces to network namespace (VRF)
  • Bring up the loopback interface in the vpn network namespace.
  • [IMP] 5. Accessing interface in another VRF or namespace via Linux:
  • ip [-all] netns exec [ NAME ] [cmd]
  • If we want to run a command on any VRF, then, use this command. For example, if you want to do tcpdump via Linux on an interface in another VRF
  • If -all option was specified then cmd will be executed synchronously on the each named network namespace even if cmd fails on some of them.
  • ip netns exec ns-tmod ip addr list will show only the related interfaces and addresses, and will not show any interfaces or addresses from the global namespace.

[admin@ck338 ~]$ sudo ip netns exec ns-tmod ip addr list

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

       valid_lft forever preferred_lft forever

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default

    link/ipip 0.0.0.0 brd 0.0.0.0

[admin@ck338 ~]$

  • Another useful command that this can be used with is for tcpdump and piping it to Wireshark:
  • The below command does packet capture on interface Vlan10 (which is in VRF dhcpvrf) only on port 67 and port 68 (since dhcp control messages use these ports)
  • ip netns exec ns-dhcpvrf tcpdump -i vlan10 port 67 or port 68
  • Now, in order to view the tcpdump on Wireshark:

ssh root@mc327 "ip netns exec ns-dhcpvrf tcpdump -i vlan10 port 67 or port 68 " | wireshark -k -i -

Tcpdump:

The various flags that can be used with tcpdump are:

  • -i <interface>
  • # tcpdump -i eth0
  • -i any
  • Listen on all interfaces just to see if you’re seeing any traffic.
  • # tcpdump -i any
  • -c <count> -i <interface>
  • Used to capture a specified number of packets
  • # tcpdump -c 5 -i eth0
  • -D
  • Used to display all available iinterfaces for tcpdump
  • # tcpdump -D
  • -e [useful]
  • To get ethernet header as well
  • Should be used if filtering packets based on L2 headers or for L2-only packets
  • -w [useful]
  • Used to capture and save packets in a pcap file
  • # tcpdump -w 0001.pcap -i eth0
  • -r
  • Used to read captured packets file
  • # tcpdump -r 0001.pcap
  • -n
  • Usually when we do tcpdump, the IP address is replaced with the DNS address
  • In order to get the IP address, use -n flag. It will ignore the hostname and print out IP address itself
  • # tcpdump -n -i eth0
  • [useful] To filter packets based on type of packet:
  • To capture packets based on TCP port, run the following command with option tcp.
  • # tcpdump -i eth0 tcp
  • Similarly, replace tcp with icmp to check for ping packets only
  • Similarly, replace with ether for checking only LLDP or LACP packets. You can increase further filtering by adding destination address so that only LLDP or LACP packets destined to me shows up:
  • tcpdump -nevvvi et1 ether dst host 01:80:c2:00:00:0e
  • The -n -e -vvv -i flags are used in above to get advanced tuning
  • dst host is used to filter based on destination mac address
  • Other types that can be used are: fddi, tr, wlan, ip, ip6, arp, rarp, decnet, tcp and udp
  • [useful] To capture based on port, src ip, dst ip:
  • Similarly, for packets on particular port: # tcpdump -i eth0 port 22
  • Similarly, for packets from particular source IP: # tcpdump -i eth0 src 192.168.0.2
  • Similarly, for packets from a particular destination IP: # tcpdump -i eth0 dst 50.116.66.139
  • [useful] -v, -vv, -vvv:
  • To select amount of packet information in verbose mode

resolv.conf:

  • resolv.conf is the name of a computer file used in various operating systems to configure the system's Domain Name System (DNS) resolver.
  • The file is a plain-text file usually created by the network administrator or by applications that manage the configuration tasks of the system.
  • The file resolv.conf typically contains directives that specify the default search domains; used for completing a given query name to a fully qualified domain name when no domain suffix is supplied. It also contains a list of IP addresses of nameservers available for resolution. An example file is:

search example.com local.lan
nameserver 127.0.0.1
nameserver 172.16.1.254
nameserver 172.16.2.254
nameserver 192.168.137.
2

  • resolv.conf is usually located in the /etc directory of the file system.
  • The file is either maintained manually, or when DHCP is used, it is usually updated with the utility resolvconf.

Monday 30 July 2018

Linux Networking Utilities for Arista EOS- Part 1

Linux Networking Utilities for Arista EOS 

LINUX NETWORKING UTILITIES:

.

Ifconfig:

  • ifconfig in short “interface configuration” utility for system/network administration in Unix/Linux operating systems to configure, manage and query network interface parameters via command line interface or in a system configuration scripts.
  • The “ifconfig” command is used for displaying current network configuration information, setting up an ip address, netmask or broadcast address to an network interface, creating an alias for network interface, setting up hardware address and enable or disable network interfaces.
  • 1. View All Network Setting
  • The “ifconfig” command with no arguments will display all the active interfaces details. The ifconfig command also used to check the assigned IP address of an server.

[root@tecmint ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0B:CD:1C:18:5A
inet addr:172.16.25.126  Bcast:172.16.25.63  Mask:255.255.255.224
inet6 addr: fe80::20b:cdff:fe1c:185a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:2341604 errors:0 dropped:0 overruns:0 frame:0
TX packets:2217673 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:293460932 (279.8 MiB)  TX bytes:1042006549 (993.7 MiB)
Interrupt:185 Memory:f7fe0000-f7ff0000
lo        Link encap:Local Loopback
inet addr:127.0.0.1  Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING  MTU:16436  Metric:1
RX packets:5019066 errors:0 dropped:0 overruns:0 frame:0
TX packets:5019066 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2174522634 (2.0 GiB)  TX bytes:2174522634 (2.0 GiB)
tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.1.1.1  P-t-P:10.1.1.2  Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

  • 2. Display Information of All Network Interfaces
  • The following ifconfig command with -a argument will display information of all active or inactive network interfaces on server. It displays the results for eth0, lo, sit0 and tun0.

[root@tecmint ~]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:0B:CD:1C:18:5A
inet addr:172.16.25.126  Bcast:172.16.25.63  Mask:255.255.255.224
inet6 addr: fe80::20b:cdff:fe1c:185a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:2344927 errors:0 dropped:0 overruns:0 frame:0
TX packets:2220777 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:293839516 (280.2 MiB)  TX bytes:1043722206 (995.3 MiB)
Interrupt:185 Memory:f7fe0000-f7ff0000
lo        Link encap:Local Loopback
inet addr:127.0.0.1  Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING  MTU:16436  Metric:1
RX packets:5022927 errors:0 dropped:0 overruns:0 frame:0
TX packets:5022927 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2175739488 (2.0 GiB)  TX bytes:2175739488 (2.0 GiB)
sit0      Link encap:IPv6-in-IPv4
NOARP  MTU:1480  Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.1.1.1  P-t-P:10.1.1.2  Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

  • 3. View Network Settings of Specific Interface
  • Using interface name (eth0) as an argument with “ifconfig” command will display details of specific network interface.

[root@tecmint ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0B:CD:1C:18:5A
inet addr:172.16.25.126  Bcast:172.16.25.63  Mask:255.255.255.224
inet6 addr: fe80::20b:cdff:fe1c:185a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:2345583 errors:0 dropped:0 overruns:0 frame:0
TX packets:2221421 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:293912265 (280.2 MiB)  TX bytes:1044100408 (995.7 MiB)
Interrupt:185 Memory:f7fe0000-f7ff0000

  • 4. How to Enable an Network Interface
  • The “up” or “ifup” flag with interface name (eth0) activates an network interface, if it is not in active state and allowing to send and receive information. For example, “ifconfig eth0 up” or “ifup eth0” will activate the eth0interface.

[root@tecmint ~]# ifconfig eth0 up
OR
[root@tecmint ~]# ifup eth0

  • 5. How to Disable an Network Interface
  • The “down” or “ifdown” flag with interface name (eth0) deactivates the specified network interface. For example, “ifconfig eth0 down” or “ifdown eth0” command deactivates the eth0 interface, if it is in active state.

[root@tecmint ~]# ifconfig eth0 down
OR
[root@tecmint ~]# ifdown eth0

  • 6. How to Assign a IP Address to Network Interface
  • To assign an IP address to an specific interface, use the following command with an interface name (eth0) and ip address that you want to set. For example, “ifconfig eth0 172.16.25.125” will set the IP address to interface eth0.

[root@tecmint ~]# ifconfig eth0 172.16.25.125

  • 7. How to Assign a Netmask to Network Interface
  • Using the “ifconfig” command with “netmask” argument and interface name as (eth0) allows you to define an netmask to an given interface. For example, “ifconfig eth0 netmask 255.255.255.224” will set the network mask to an given interface eth0.

[root@tecmint ~]# ifconfig eth0 netmask 255.255.255.224

  • 8. How to Assign a Broadcast to Network Interface
  • Using the “broadcast” argument with an interface name will set the broadcast address for the given interface. For example, “ifconfig eth0 broadcast 172.16.25.63” command sets the broadcast address to an interface eth0.

[root@tecmint ~]# ifconfig eth0 broadcast 172.16.25.63

  • 9. How to Assign a IP, Netmask and Broadcast to Network Interface
  • To assign an IP address, Netmask address and Broadcast address all at once using “ifconfig” command with all arguments as given below.

[root@tecmint ~]# ifconfig eth0 172.16.25.125 netmask 255.255.255.224 broadcast 172.16.25.63

  • 10. How to Change MTU for an Network Interface
  • The “mtu” argument set the maximum transmission unit to an interface. The MTU allows you to set the limit size of packets that are transmitted on an interface. The MTU able to handle maximum number of octets to an interface in one single transaction. For example, “ifconfig eth0 mtu 1000” will set the maximum transmission unit to given set (i.e. 1000). Not all network interfaces supports MTU settings.

[root@tecmint ~]# ifconfig eth0 mtu 1000

  • 11. How to Enable Promiscuous Mode
  • What happens in normal mode, when a packet received by a network card, it verifies that the packet belongs to itself. If not, it drops the packet normally, but in the promiscuous mode is used to accept all the packets that flows through the network card.
  • Most of the today’s network tools uses the promiscuous mode to capture and analyze the packets that flows through the network interface. To set the promiscuous mode, use the following command.

[root@tecmint ~]# ifconfig eth0 promisc

  • 12. How to Disable Promiscuous Mode
  • To disable promiscuous mode, use the “-promisc” switch that drops back the network interface in normal mode.

[root@tecmint ~]# ifconfig eth0 -promisc

  • 13. How to Add New Alias to Network Interface
  • The ifconfig utility allows you to configure additional network interfaces using alias feature. To add alias network interface of eth0, use the following command. Please note that alias network address in same sub-net mask. For example, if your eth0 network ip address is 172.16.25.125, then alias ip address must be 172.16.25.127.

[root@tecmint ~]# ifconfig eth0:0 172.16.25.127

  • Next, verify the newly created alias network interface address, by using “ifconfig eth0:0” command.

[root@tecmint ~]# ifconfig eth0:0
eth0:0    Link encap:Ethernet  HWaddr 00:01:6C:99:14:68
inet addr:172.16.25.123  Bcast:172.16.25.63  Mask:255.255.255.240
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
Interrupt:17

  • 14. How to Remove Alias to Network Interface
  • If you no longer required an alias network interface or you incorrectly configured it, you can remove it by using the following command.

[root@tecmint ~]# ifconfig eth0:0 down

  • 15. How to Change the MAC address of Network Interface
  • To change the MAC (Media Access Control) address of an eth0 network interface, use the following command with argument “hw ether“. For example, see below.

[root@tecmint ~]# ifconfig eth0 hw ether AA:BB:CC:DD:EE:FF

Sunday 27 May 2018

Linux Fundamentals for Networking- Part 3

1) Diff b/w foreground and background process? How to bring to foreground?
  • Unlike with a foreground process, the shell does not have to wait for a background process to end before it can run more processes. 
  • To run a command as a background process, type the command and add a space and an ampersand to the end of the command. For example:    $ command1 &
  • Here, While that is running in the background, the shell prompt will return. 
  • To start a foreground process, enter a command at the prompt, e.g.,    $ command1
  • Here, the next prompt will not appear until command1 finishes running.
  • To bring background process to foreground, type $fg to bring the last process back to foreground. 
  • To get a list of all the background jobs, use $jobs -l and then see our needed process job number and type $fg %<job no>
2) Can we pass input to background process?
  • Depends on the type of input 
  • If you want to type the input, then you will have to put it back in the foreground to type your input, then put it into the background again. 
3) Process system calls?


  • Exit- terminate the current process 
  • Fork- create a child process 
  • Waitpid (OR) Wait4- wait for process termination 
  • Getpid- get process identification 
  • Ptrace- allows a parent process to control the execution of a child process 
  • Pause- suspend process until signal 
  • Nice- change process priority 
  • Kill- send signal to process 
  • Pipe- create an interprocess channel 
  • Times- get process times 
  • Brk- change the amount of space allocated for the calling process's data segment 
  • Setpgid- set process group ID 
  • Getpgid- get process group ID 
  • Sys_getsid- get process group ID of session leader 
  • Getppid- get parent process ID 
  • Setsid- creates a session and sets the process group ID 
  • Idle- make process 0 idle 
  • Personality- set the process execution domain 
  • Clone- create a child process 
  • Mlockall- disable paging for calling process 
  • Munlockall- reenable paging for calling process 
  • Prctl- operations on a process 
  • Capget- get process capabilities 
  • Capset- set process capabilities 
  • Vfork- create a child process and block parent 
4) Command to see list of sizes of files?  (similar to df -h for directory)
  • Use $ls -s to list file size, or if you prefer $ls -sh for human readable sizes.
  • For files use du, and again, $du -h * for human readable sizes. (du = disk usage of files and directories)
-a
All files  and folder
-h
Human readable sizes


5) Commands to compress- the tar and zip command flavours?

Compressing Files: 
  • gzip {filename} - Eg) gzip mydata.doc (OR) gzip *.jpg 
  • bzip2 {filename} 
  • zip {filenameofzip.zip} {filename-to-compress} 
  • tar -cfzv {filenameoftgz.tgz} {files} (OR)
  • tar -cfzv {filenameoftgz2.tbz2} {files} 
Decompressing Files: 
  • gzip -d {.gz file} (OR) gunzip {.gz file} 
  • bzip2 -d {.bz2-file} (OR) bunzip2 {.bz2-file} 
  • unzip {.zip file} 
  • tar -xfzv {.tgz-file}  (OR)
  • tar -xfzv {.tbz2-file}
6) FIND command- options and arguments?
  • Basic Syntax:
  • $find / -name filenametofind
    • The first part of the find command is obviously the word find. 
    • The second part is where to start searching from. Example: ~, /, /dev, etc...
    • The next part is an expression which determines what to find. Example: -empty (finds empty files and folders),  -executable (find all executable files), -readable (find all readable files), -name (search for all files with the specified name), -atime (find Files Accessed More Than A Certain Number Of Day Ago)
    • Finally the last part is the name of the thing to find. Example: 
      • $find / -name *.mp3 (pattern searching for all files with the extension mp3)
      • $find / -readable
      • $find / -executable
      • $find / -empty
      • $find ~ -atime 100 (find all the files within your home folder accessed more than 100 days ago)
    • More options on: https://www.lifewire.com/uses-of-linux-command-find-2201100
    • To see only the directories in / with name apple, $find / -type d -name apple
    • To see only the files in / with name apple, $find / -type f -name apple
7) Diff Command:
  • Compare 2 files 
  • $diff file1 file2
  • we can use diff to automatically display for us which lines differ between the two files
8) Environmental variables and commands 
    • Linux environment variable is an object that contains value. In simple terms it is a pair of data object and their respective values.
    • $printenv or $env command can be use to list linux environment variables.
    • Various environment variables are:
      • $echo $PATH where PATH is an environment variable name and echo is just to print
      • $TEMP – location where processes can store temporary files
      • $HOME - indicate where a user's home directory is located in the file system.
      • $PWD- show present working directory
      • $SHELL contains the path to the user's preferred shell
      • $TERM contains the type of the running terminal, e.g. xterm-256color.
      • $VISUAL contains command to run the full-fledged editor that is used for more demanding tasks, such as editing mail (e.g., vi, vim, emacs etc).
    • To add or define our own environment variables:
      • $vi ~/.bash_profile (open bash profile)
      • PATH= $PATH: $HOME/bin: /home/user1/custom_script (add our directory /home/user1/custom_script in PATH variable)
9) All vi options:

Linux Fundamentals for Networking- Part 2

SORT:
    • The Linux sort command can be used to sort the contents of a file in a number of ways. By default, the Linux sort command sorts the contents in alphabetical order depending on the first letter in each line. For example, the $sort /etc/passwd command would sort all users by username.
    • Important options of the sort are
-b (Ignores spaces at beginning of the line)
-d (Uses dictionary sort order and ignores the punctuation)
-f (Ignores caps)
-i (Ignores nonprinting control characters)
-m (Merges two or more input files into one sorted output)
-r (Sorts in reverse order)
-u (If line is duplicated only display once)
$ps | sort -k 3
  • Sorts the list of process in order of the 3rd column
$ cat text1.log text2.log | sort -k 1
  • Sorts the cat of two files on the first letter of each line

WC:
    • The Linux wc (word count) command, can return the number of lines, words, and characters in a file. Important options of the Linux wc command are
-c (Print the byte counts)
-m (Print the byte counts)
-l (Print the new line counts)
-w (Print the word counts)

More and Less Command:
  • The “more” command is used to view text output of commands or files one page at a time. When the user is ready for the next block of text, they press the space bar.
  • Less extends the functionality of more by adding forward and backwards movement, the ability to search multiple files, view gzipped files without uncompressing them first, set marks for navigation and can invoke an editor when viewing files.

Head and Tail Command:
  • tail prints the last 10 lines of each FILE to standard output.: tail myfile.txt
    • To print last 100 lines, we can use tail myfile.txt -n 100
  • head, by default, prints the first 10 lines of each FILE to standard output.

Help for Linux Commands:
  • Man: If you don’t know the exact command name for a specific functionality, use man -k option to locate the command.
$ man UNIXCOMMAND
  • Whatis: To display a single line description about the command, you can use whatis command.
$ whatis cron
  • cron (8)         - daemon to execute scheduled commands (Vixie Cron)
  • Use -h or –help option of the command itself: Sometimes you may know the functionality of a command very well, but cannot recollect all the available options for a specific command. Use -h option of the command to review all available options of the command.
$ UNIXCOMMAND -h
  • Info: When you are not able to find the required information from the Unix man page, try the info documents using the Unix info command as shown below.
$ info UNIXCOMMAND

Different Ways to see the running processes:
Ps
Top
  • Works like PS only
  • But, it is Real-time
  • Lists out CPU percentage usage also- so we can check whether our foreground process is only taking more memory
Memory Leak:
At the end of activity, application must release the memory
But, if the releasing doesn’t happen correctly, then, memory accumulation happens over a long time which results in a leak.
Due to this, memory starvation happens for other process

To see memory, 
show version (EOS command to show RAM memory)
Go to bash and then $df  or $df -h(df=diskspace for filesystem. Used to see flash and also all other filesystem mounts)

To see the agent logs, 
Go to bash and then $/var/log/agents and then $ls
It shows the log for currently running process

To see system logs,
Go to $/var/log/messages


OTHER COMMANDS:
System Crash dump is mounted in /var/core . It is a complete mirror image of system.
If any agent log becomes very large, we compress it using tar, gz, zip, etc

If we want to get more space, we clear varcore and other logs

To search for files, we use find command (it is important). For example, we can use find to find the debug.log file. 

$History command is used to see what we have executed on the shell (everyone’s session commands also shown as it is linux). It is linux command but it is also present in EOS CLI (due to linux integration) as #show history. It lists only of our current session, not everyone.

Environment Variables - The binaries are stored at a specific location and whenever a process asks for the file, it tells to look at the specific location using environment variables. To see all env variables, use $printenv
  • $echo $PATH where PATH is an environment variable name and echo is just to print
  • $TEMP – location where processes can store temporary files
  • $HOME - indicate where a user's home directory is located in the file system.
  • $PWD- show present working directory
  • $SHELL contains the path to the user's preferred shell
  • $TERM contains the type of the running terminal, e.g. xterm-256color.
  • $VISUAL contains command to run the full-fledged editor that is used for more demanding tasks, such as editing mail (e.g., vi, vim, emacs etc).
  • https://wiki.archlinux.org/index.php/environment_variables

BASHRC file:
  • Located in user’s home directory
  • .bashrc is a shell script that Bash runs whenever it is started interactively. 
  • You can edit it to set our environment variables
  • For example, we can set aliases in .bashrc for very long commands. It works only for us.
  • Note that alias works in EOS also and here it works for everyone

Installing Packages:
  • Fedora uses YUM Package Manager
  • Here, the package is RPM format
  • Inside Linux, everything is managed as a file including processes, devices, drivers, folders, etc…So, we can vi anything
  • Install using the command in bash: $rpm -i <package>.rpm

Background and Foreground Process:
  • Unlike with a foreground process, the shell does not have to wait for a background process to end before it can run more processes.
  • To run a command as a background process, type the command and add a space and an ampersand to the end of the command. For example:
$ command1 &
Here, While that is running in the background, the shell prompt will return.
  • To start a foreground process, enter a command at the prompt, e.g.,
$ command1
Here, the next prompt will not appear until command1 finishes running.
We can see routing tables in Linux using route or netstat -rn. It is called as Kernel Route Table and the routes are called bash routes
EOS maintains its own route tables.
Loopback Address:
  • IPC mechanisms like sockets and pipes use this
  • Used by developers to test their applications. For example, two applications on same machine can open a socket to loopback address and read data b/w them.
  • Testing the IP stack
  • Inside EOS, loopback address is a unique identifier for each switch
Currently, we have 550k routes on the internet
Tcpdump:
  • It is used to capture packets. (It can be used even from EOS and the command varies slightly)
  • For single interface, $tcpdump -i et 1/1
  • To write the output to a file, $tcpdump -i ma 1 -w /mnt/flash/filename.pcap
  • To see the capture for all interfaces, $sudo tcpdump
  • To listen to the traffic before it even goes to the CPU, $tcpdump -i fabric. Used for seeing vlan tagging.
To copy a file from linux to laptop.
  • $scp filename.pcap admin@switch1:/users/admin/Desktop
  • Note that the ‘:’ after ip address is compulsory in linux and not needed in EOS
To copy a file from laptop to linux,
  • $scp admin@my-laptop:/Users/admin/Desktop/filename.pcap .
  • The ‘.’ as the destination means it will copy the file to the current directory in linux
Accessing switch using ftp instead of ssh and copy the file to laptop:
  • admin$sftp root@switch1
sftp> ls
sftp> get filename.pcap
sftp> exit
admin$ ls | grep filename.pcap
  • The file will be there in our computer .ie. we transfered the file from switch to laptop using ftp
To connect to a local switch instead of remote switch, 
  • We first configure our ip address manually to the same subnet as the switch
192.168.1.2 and 255.255.255.0 where the ‘*.*.*.2’ is the port number on the switch
  • Then, we $ssh admin@192.168.1.100 using your password. Ie. we connect to the management port of the switch