Monday, April 23, 2012

ssh


SSH Escape Sequence:
Supported escape sequences:
~ . ----- terminate connection that got hanged
~ ^ Z -----suspend ssh --- to send the ssh-connection to background
~ #  ----- list forwarded connections
~ &  ----- background ssh (when waiting for connections to terminate)
~ ?  ----- this message
~ ~  ----- send the escape character by typing it twice
(Note that escapes are only recognized immediately after a newline.)


References:
http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node30.html


Tuesday, March 13, 2012

Network packet flow

For a long time, I was thinking of updating the network packet flow, but couldn't get time. I came across the following excellent discussion on it. I'm copy pasting it here for(myself :-)) now. I will trim it in near future. till then please go through the nice explanation done here:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

SystemsGM,

I'm assuming that WS1 and WS2 are in seperate networks based on your description.

The scenario of:

WS1 <-Ethernet-> SW1 <-Ethernet-> R1 <-Serial-> R2 <-Ethernet-> SW2 <-Ethernet-> WS2

WS1 IP: 192.168.1.2/24

WS2 IP: 192.168.2.2/24

R1 ethernet interface IP: 192.168.1.1/24

R2 ethernet interface IP: 192.168.2.1/24

WS1 has a packet of IP data destined for WS2.

The first thing WS1 does is determine if the destination of the IP packet is on the same network as itself. If it is, it checks its ARP table to determine if it already has a MAC address that corresponds with the destination IP address and puts that MAC address as the destination MAC for the outbound ethernet frame. If there is no MAC address in the local ARP table for the destination IP address, it sends an ARP request out the ethernet interface requesting 'whomever owns IP address x.x.x.x, please respond with your MAC address'.

If the destination IP address is on a different network, in this case it is, the workstation determines that the packet must be forwarded to the default gateway to be routed to the destination network.

WS1 has 192.168.1.1 as the default gateway, so it verifies if it has the MAC address for that IP address in its local ARP table. If it does not, it sends an ARP request asking 'whomever owns 192.168.1.1, please respond with your MAC address', in which the router will reply with it's MAC address for it's ethernet interface.

WS1 will then put the frame on the ethernet wire with a source MAC address of itself, and a destination MAC address of the ethernet interface of R1.

SW1 will forward the frame based on it's internal MAC forwarding table to the ethernet port that R1 is connected to on the switch. The switch does not alter or strip any layer 2 MAC address information.

R1 will receive the frame on its ethernet interface and will strip off the layer 2 MAC address information and look at the destination IP address and forward/route the packet accordingly.

If a route for a network that contains the 192.168.2.2 (destination IP) is in its routing table, it will forward the packet.

Let's assume that R1 has the 192.168.2.0/24 network in its routing table and the best way to that network is through its serial interface to R2. It will then forward the packet to R2 through that serial interface.

At this point, all of the previous layer 2 information is completely stripped from the packet. The source and destination IP address are kept in tact.

R2 receives the packet (technically a layer 2 frame) on its serial interface and checks the destination IP address of the packet, which in this case is 192.168.2.2. It has a directly connected ethernet interface that is associated/assigned the network that the destination IP address falls within, so it will prepare that packet to be forwarded out its ethernet interface.

The first thing that R2 does is check its local ARP table to determine if it knows what layer 2 MAC address is assigned to 192.168.2.2. If it doesn't have an entry, it will send and ARP request out the ethernet interface, with which WS2 will respond with its MAC address.

Once the destination MAC address is determined for WS2, R2 will add layer 2 information to the IP packet (encapsulating) making it a layer 2 ethernet frame with the source MAC address the MAC address of the ethernet interface of R2 and the destination MAC address the MAC address of WS2. Once the ethernet frame is created, it is forwarded out R2's ethernet interface to SW2.

SW2 then checks its MAC forwarding table to determine which port the destination MAC (WS2) is associated with, and will forward that frame to the port that WS2 is connected.

WS2 then receives the frame, strips the layer 2 information off and processes the IP packet accordingly.

Sorry for such a long winded explanation. Hopefully it was of some use.

Basic rule to remember - source and destination IP address never change between the source and destination device (unless you have a NAT device in the path), but the layer 2 information can change. Layer 2 information doesn't change until the packet has to traverse a layer 3 device (router).

HTH

Mike Morris

-----------------------------------------------------------

Hi guys,

great discussion here, you brought up a question I had long time ago. Is the MAC address of the switch ever attached to any packet/frame? I never heard the author say something like this, but since there are so many MAC addresses on the switch (one/port), what are those for?

As for systemGM, here is the answer to your question:

Let's start with your example, (of one router, 2 switches, and 2 PCs).

1. PC1 want to send PC2 some data, so the data moves from Layer 7, where data was generated, down to Layer 4. Now segmentation occurs, and L4 header is placed in front of the data. This is a segment.

2. The data continues its way down and come to L3, where destination IP address (IP address of PC2) and source IP address (IP address of PC1) is put inside the L3 header, which wraps around L4 Header + data. This is packet.

3. When data reaches L2, source MAC address (PC1's MAC address) and destination MAC address (Router's MAC address) is placed in the data link header. Note that layer 2 has a FCS trailer. This is a frame.

4. The frame is translated (from human language) to bits (computer language, 0 and 1) and send out on the physical media toward the switch.

Theoretically, the frame = (L2 header (L3 header (L4 header (data) ) ) L2 trailer)

Sw1 receives the bits, translated back to the frame and read the L2 header. After reading it, Sw1 now knows this frame is destined for the router and forward the frame to the interface that is connected to the router. L2 header remains intact and the frame is again translated into bits and send out to the router.

Router now receives the bits, turn it into a frame. Router now knows the frame is for itself, and discard the frame. This is like you received a letter for you, and you open it to see the content. After L2 header and trailer are discarded, what is left is L3 header, which contains the destination IP address. After reading the destination IP address and know that the packet isn't for the router, the router then made a decision to forward the packet. Following the previous analogy, you have received a letter for you, but it's titled to your best friend; of course you would want to give it to her. This is what routers do, they receive things never intended for them, and forward the things to where they are supposed to be. It's a little pathetic if you think about it.

Okay, now the router has made a decision where to send this packet, again, it wraps it up into a frame, which now has source MAC address of the router and the destination MAC address of PC2 (remember that MAC addresses are obtain using ARP). The frame turns into bits and send to Sw2.

Sw2 receives the frame, read L2 header and matches the destination MAC address to an entry in its CAM table (equivalent to routing tables for routers). Once an entry has been found, the frame is forwarded out on corresponding interface.

PC2 now receives the frame, decapsulate it 3 times (bits -> frame -> packet -> segment) until it becomes data only and can be read by PC2's application programs.

In summary, from PC1 to router: S MAC = PC1's MAC, D MAC = router's MAC, S IP = PC1's IP, D IP = PC2's IP. From router to PC 2: S MAC = router's MAC, D MAC = PC2's MAC, S IP = PC1's IP, D IP = PC2's IP

Best,

A

+++++++++++++++++++++++++++++++++++++++++++++++


Reference:

https://learningnetwork.cisco.com/thread/11735

Tuesday, January 31, 2012

Latex

Latex on Windows:


References:
http://faculty.smu.edu/barr/latex/

Friday, September 23, 2011

Getting error box in vbscript

In vbscripting if there are errors on code we can see the errors on runtime through error box.

If the error on your machine is not popping on executing the vbscript through error box then you can follow below approach to enable it.

Generally issue comes if windows is taking cscript as a default engine to execute script. To change the default engine from cscript to wscript. you can do the following:

1. Right Click on Vb script file(the file you create with .vbs extension) ---> select "Open With" ---> select "Choose Program"
2. Click "Browse" button.
3. Navigate to "C:\Windows\System32\wscript.exe"
4. Click OK.

Done....You should see error box if there are any errors in the scripting file from now onwards....

Friday, September 2, 2011

rdesktop on linux

rdesktop on fedora 14 clippboard copy was not working. With the following approach I see it's working.


yum install tritonus-esd.x86_64
yum install arts.x86_64
yum install arts-devel.x86_64

Now try the following command:
rdesktop -r sound:local -r clipboard:PRIMARYCLIPBOARD -r disk:anyname=/home/username -f [remote-machine-address]

CTRL + ALT + Enter: for toggling Full screen mode in rdesktop

Reference:
http://blog.offenders.org/?p=85

how to write a linux command wrapper

In case if you want to extend the command functionality we can write a wrapper over standard linux command. We can achieve this through bash script and it is simpler.

Here is the example for it:

rdesktop is an linux command which is used to connect windows machine.

rdesktop -f [remote-machine-address] is the basic command to connect to windows machine.

Now if you want to enhance it to support extra options we can use the following options:
rdesktop -r sound:local -r clipboard:PRIMARYCLIPBOARD -r disk:root=/

sound:local -- to enable sound redirection.
clipboard:PRIMARYCLIPBOARD -- To allow copy/paste between rdesktop & host machine.
disk:root=/ -- To share my root directory with remote machine.

mv /usr/bin/rdesktop /usr/bin/rdesktop.bin

Create a file called /usr/bin/rdesktop.wrapper and add this to the file.

#!/bin/bash

/usr/bin/rdesktop.bin -r sound:local -r clipboard -r disk:root=/ $*
## EOF

Make the file executable.
chmod +x /usr/bin/rdesktop.wrapper

Then create a symbolic link to the wrapper.
ln -s /usr/bin/rdesktop.wrapper /usr/bin/rdesktop


You can achieve the same effect through "alias" option in bash but we(I) can use the example as starting point for shell scripting :-)


Reference:
http://blog.offenders.org/?p=85

Thursday, September 1, 2011

Things to update in blog

N-T-P: Need to update

Below are the list that I came across and waiting to update in my blog:

  1. select vs poll vs epoll ----- select can be used as server listening for client
  2. How does xinetd works
  3. Connecting to a Linux desktop through VNC.
  4. Need to discuss on how to handle when linux is stuck(we can use ctrl-alt-f2 to go to the terminal prompt and the see the process which stuck and kill it) and ctrl-alt-f1(in fedora) ctrl-alt-f7(in ubuntu) to switch back to gui prompt.
  5. on linux firewalls, iptables -L -n will list the firewalls and "service iptables stop" will stop the firewalls and "service iptables start" will start the firewall and "service iptables status" will give the status of the firewall
  6. UDP server is different from TCP server, it doesn't need to listen & accept
  7. When the TCP server establishes the connection with the client through accept, a new connection will be created with new fd, does this fd will be having different TCP port??
  8. Write fds in select is used to avoid blocking writes.
  9. "module is unknown" error on ubuntu.. solution for this...a) Open /etc/pam.d/login b) Search for pam_limits.so in the file c) replace /lib/security/pam_limits.so to /lib/i386-linux-gnu/security/pam_limits.so....Now the error shouldn't come and you should be able to login :-).... or for the last try doing "sudo pam-auth-update --force" 
  10. http://www.iovene.com/34/ -- need to update this in the blog 
  11. http://www.cisco.com/en/US/docs/switches/lan/catalyst4500/12.2/50sg/configuration/guide/dot1x.html#wp1240472 -- Dynamic vlan assignment