Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
105 views

LS, LL, W, Whoami, CD, PWD, Mkdir, MV, Rmdir, CP: Lab Session (6) : Networking

This document provides information about various networking commands and utilities in Linux. It describes commands for basic network configuration (ifconfig, route), obtaining IP addresses via DHCP (dhclient), comprehensive network tool (ip), and configuring interfaces in /etc/network/interfaces. It also covers firewall configuration with ufw/iptables, network diagnostics tools like ping, nslookup, Wireshark, remote access with ssh, file transfer via scp/sftp/ftp, and network communication with nc/socat. The document aims to introduce students to network management on Linux.

Uploaded by

Karan Kalra
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
105 views

LS, LL, W, Whoami, CD, PWD, Mkdir, MV, Rmdir, CP: Lab Session (6) : Networking

This document provides information about various networking commands and utilities in Linux. It describes commands for basic network configuration (ifconfig, route), obtaining IP addresses via DHCP (dhclient), comprehensive network tool (ip), and configuring interfaces in /etc/network/interfaces. It also covers firewall configuration with ufw/iptables, network diagnostics tools like ping, nslookup, Wireshark, remote access with ssh, file transfer via scp/sftp/ftp, and network communication with nc/socat. The document aims to introduce students to network management on Linux.

Uploaded by

Karan Kalra
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Linux Basic commands

 ls, ll, w, whoami, cd, pwd, mkdir, mv, rmdir, cp

Linux Utilities

 top – Current CPU and process utilisation

 vmstat - reports processes, memory, paging, block IO, traps, and cpu activities

 ps – snapshot of current processes

 free – memory usage

 iostat – CPU load and disk activity

 netstat – network statistics

 tcpdump – detailed network traffic analysis

 System Monitor – displays basic system information and monitor system resources

Schedule a task

 Put a file named “.crontab” in your home directory containing the following:

<minute> <hour> <day of month> <month> <day of week> <command>


eg.:
0 4 * * 7 shutdown -r now
This will reboot the system at 4 AM on each Sunday

Process and open/used files details

 All process details can be accessed from opening the directory /proc/<pid>

Adding applications to run on startup

 For services, link /etc/init.d/<service> to /etc/rc<N>.d/S<NN><service>, where <N> is the runlevel,


<NN> is the running order, and <service> is the service name

 Lab session (6): Networking

Aim: To introduce the student to various network management utilities on Linux

Prerequisite knowledge: A basic understanding of the architecture of internet, basic understanding of


architecture of X

In this lab session, the student will learn how to use common Linux utilities like ifconfig, route, ip, dhclient,
nc/socat, ufw/iptables etc. Some application level tools for diagnosing the network connection will also be
covered. Apart from this, the student will also learn how to configure a wireless router and create wireless
networks etc.
Network configuration
ifconfig
ifconfig is the basic NIC configuration tool on Linux, used almost everywhere extensively.

1. Listing network interfaces and their configuration:

ifconfig -a

o The first interface that it shows, lo, is the localhost interface. It usually has the IP address
127.0.0.1 and represents the local machine itself. Any connection to 127.0.0.1 will be made to
the local machine itself.

2. Closing an interface:

ifconfig <interface> down

3. Setting the IP address:

ifconfig <interface> <addr>

4. Setting the subnet mask:

ifconfig <interface> netmask <mask-addr>

5. Setting the broadcast address:

ifconfig <interface> broadcast <bcast-addr>

6. Setting the MAC address:

ifconfig <interface> hw ether <mac-addr>

More comprehensive documentation is available at man 8 ifconfig

route
route is used for defining the routing tables. ie. the next node that a packet should hop to.

1. Listing the current defined routes:

route -n

2. Adding the default gateway:

route add default gw <addr> [dev <interface>]

3. Adding a specific route:

route add <dest-addr> gw <addr>


4. Deleting a route:

route del <dest-addr>

More comprehensive documentation is available at man 8 route

dhclient
dhclientis used for DHCP discovery on a network. To automatically get the IP NIC configuration from a
DHCP server on the network, do:

dhclient <interface>

More comprehensive documentation is available at man 8 dhclient

ip
ip is the swiss-army knife tool for network configuration. Its usage is mostly similar to the above tools, with
slight differences. man 8 ip lists the entire argument structure of this tool. Some examples are given below:

1. Display device link configuration:

ip link show <interface>

2. Change MAC address of a device:

ip link set dev <interface> address <mac-addr>

3. Add an IP address to an interface:

ip address add dev <interface> address <addr>

4. Add a route:

ip route add to <type> <dest-addr> via <gw-addr> dev <interface>

Apart from these, the ip command can also modify the ARP tables, tunnels, multicast addresses etc. More
comprehensive documentation is available at man 8 ip

/etc/network/interfaces
The network interfaces can also be configured permanently in the file /etc/network/interfaces. Here's an
example:

/etc/network/interfaces
auto eth0 # Automatically start eth0 if available
iface eth0 inet static # Configure eth0 statically using the internet protocol
address 192.168.1.174
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.1
up /home/user/crclient -u user08099 # run the cyberoam client and automatically
login when this interface is brought up
pre-down /home/user/crclient -l # run the cyberoam client and automatically
logout before this interface is brought down
 
auto lo # automatically start the interface lo
iface lo inet loopback # confiugre lo using the internet protocol, and make it a
loopback interface
 
iface eth1 inet dhcp # configure eth1 using dhcp
pre-up /etc/init.d/ssh start
up touch /home/user/.connected
down rm /home/user/.connected
down /etc/init.d/ssh stop

More comprehensive documentation is available at man 5 interfaces.

NetworkManager GUIs
Apart from the above utilities, you can use the NetworkManager GUIs to configure your network. The Ubuntu
wiki has comprehensive documentation for NetworkManager.

ufw/iptables
ufwand iptables are used for managing firewalls. The Ubuntu wiki has pretty good documentation along with
examples for ufw and iptables. We'll also look at configuring the firewall using Gufw.

Diagnostics
ping
ping is a utility which checks if a particular node is reachable by sending it ICMP echo requests. For example,
to ping google.com:

ping google.com

If you're unable to get any replies, check what the default gateway is using route -n, and then try to ping the
gateway. More comprehensive documentation is available at man 8 ping

nslookup
nslookup is a command-line domain name resolver. It can be used to check if the nameserver is reachable. eg.
to lookup google.com:

nslookup google.com

If it is unable to resolve google.com, but you were able to ping your gateway, you can try changing your
nameserver by editing /etc/resolv.conf. eg. to use Google's DNS servers, with iiitd.edu.in being the default
search domain, add the following lines to /etc/resolv.conf:

/etc/resolv.conf
search iiitd.edu.in
nameserver 8.8.8.8
nameserver 8.8.4.4

More comprehensive documentation is available at man 1 nslookup

Wireshark
Wireshark is used for capturing packets on the network. It must be started as root to be able to capture any
packets. After starting Wireshark, press Ctrl+I and select eth0, eth1, wlan0, or any other interface that you're
interested in, and start capturing the packets. You can specify a regular expression to filter the packets, if you
like.

Communication
Remote access
ssh,which stands for Secure SHell, is used for gaining shell-based remote access to a machine. To login to a
remote machine, you can do:

ssh <user>@<host>

Once you're inside a machine, you have full access to it as if you were working on it locally. To run GUI
programs, a sample login session might proceed as follows:

user@machine1$ ssh user@machine2


user@machine2$ export DISPLAY=machine1:0
user@machine2$ firefox &

(The part before the $ represents the prompt)

The DISPLAY variable tells the GUI programs the address of the X server to connect to. X is the most
commonly used GUI subsystem on Linux.

One thing to note here is that due to certain security issues, X may not allow remote clients (such as client
running on machine2) to connect to it (the X server running on machine1). A secure and easy way to get past
this is to run a nested X server with access control turned off and use that for inbound connections. eg.:

user1@machine1$ Xephyr -screen 1024x768 -ac :1 &


user1@machine1$ ssh user2@machine2
user2@machine2$ export DISPLAY=machine1:1
user2@machine2$ firefox &

Note the change in the value of the DISPLAY variable.

File transfer
FTP

ftp is the default CLI-based FTP client. To use it, do:

ftp <host>
Some of the commonly used FTP commands are:

1. ABOR - abort an ongoing transfer

2. CDUP - similar to cd ..

3. CWD - similar to cd

4. DELE - similar to rm

5. HELP

6. LIST - similar to ls

7. RETR - download a particular file

8. RMD - similar to rmdir

9. STAT - prints connection status

10. STOR - upload a file

ssh

ssh comes bundled with some other utilities, like scp and sftp.

scp is used for copying files securely to/from a remote machine over ssh. To copy a file from the local machine
to a remote machine, you can do:

scp <filename> <user>@<host>:<path>

sftp is similar to ftp, but works over ssh. To connect to a remote host for sftp, you can do:

sftp <user>@<host>

ncftpget and ncftpput are scriptable, non-interactive ftp clients. eg. Let's say I want to download the latest
Xubuntu daily image from Ubuntu's FTP server. I can create the following script:

/usr/bin/getxubuntu.sh
#!/bin/bash
ncftpget -u anonymous -p qwerty@asdf.org \
-C ftp://cdimage.ubuntu.com/cdimage/xubuntu/daily-live/current/maverick-desktop-
amd64.iso \
/home/user/xubuntu-daily-"$(date +%F)".iso

Then, I will add the following line to /etc/crontab:

/etc/crontab
0 0 * * * /usr/bin/getxubuntu.sh

nc/socat
ncand socat can be used for creating a listening socket or for connecting to a socket that's already listening.
Some examples:

1. Listen on a specific port:

nc -l <port>

2. Connect to a server:

nc <addr> <port>

3. Create a server and link stdin to it:

socat - TCP-LISTEN:<port>

4. Connect to a server and link stdin to the socket:

socat - TCP-CONNECT:<host>:<port>

You can use tar and nc for file transfers. eg.:

machine1$ tar -cvf - /home | nc -l 59590


machine2$ nc machine1 59590 | tar -xvf -

rsync

rsync is used for updating files over a network. It can either push an update to a remote server or pull an
update. It supports connecting via a secure shell connection or a dedicated rsync daemon. Some examples:

1. Local copy:

rsync </src/path/> </dest/path>

2. Pull using a secure shell:

rsync <user>@<host>:<path> </local/path>

3. Push using the rsync daemon:

rsync </local/path> rsync://<user>@<host>/<remote/path>

More comprehensive documentation is available at man 1 rsync

You might also like