Few Linux commands for novice net-admin


Adding IP, netmask and default gateway to Linux machine (note: configuration file path can be vary depending on the Linux flavor as listed below)

# ifconfig eth0 192.168.2.10 netmask 255.255.255.0 up

(eth0 is a 1st network card adapter interface. eg. eth0, eth1 (2nd NIC), lo (loopback. UP is to bring up the interface, alternative, #ifup eth0 (activate the inferface eth0, #ifdown eth0 (reactive the interface eth0).
—————————–
route add -net 192.168.2.0 netmask 255.255.255.0 dev eth0
(add a route to the network 192.168.2.x via “eth0”. The word “dev” can be omitted here)
# route add default gw 192.168.2.1 eth0

Alternatively command
# route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1 dev eth0

find . -name network
Your main network configuration file is /etc/network/interfaces (depends on Linux flavor)

#mii-tool or # ethtool eth0 ( check duplex and speed set on NIC)

Open network configuration file
#vi /etc/network/interfaces
Find and remove dhcp entry:
iface eth0 inet dhcp
Append new network settings:
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.254

Save and close the file. Restart the network:
# /etc/init.d/networking restart
Define new DNS servers
Open /etc/resolv.conf file
# vi /etc/resolv.conf
You need to remove old DNS server assigned by DHCP server:
search myisp.com
nameserver 192.168.2.250
nameserver 202.54.2.20
nameserver 202.54.2.30

Save and close the file.
Display network interface information
# ifconfig
Take down network interface eth0 / take a network interface down
# ifconfig eth0 down  ‘(or UP)
# ifdown eth0
Bring a network interface eth0 up
# ifconfig eth0 # ifup eth0
#ifdown
#ifup
Change IP address and netmask from command line
Activate network interface eth0 with a new IP (192.168.2.50) / netmask:
# sudo ifconfig eth0 192.168.2.50 netmask 255.255.255.0 up
Display the routing table
# route -n
Output:
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
localnet        *               255.255.255.0   U     0      0        0 ra0
172.16.1.0    *               255.255.255.0   U     0      0        0 eth0
172.16.2.0    *               255.255.255.0   U     0      0        0 eth1
default         192.168.1.254   0.0.0.0         UG    0      0        0 ra0
Task: Add a new gateway
#sudo route add default gw 172.16.236.0
Display current active Internet connections (servers and established connection)
# netstat -nat
Display open ports
# netstat –tulp
Display network interfaces stats (RX/TX etc)
$ netstat -i
Display output for active/established connections only
#netstat -e
# netstat -te
# netstat -tue
-t : TCP connections
-u : UDP connections
-e : Established

 

 

Normal
0

false
false
false

EN-US
X-NONE
X-NONE

 

 

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Table Normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:””;
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:”Calibri”,”sans-serif”;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:”Times New Roman”;
mso-bidi-theme-font:minor-bidi;}

Adding IP, netmask and default gateway to Linux machine (note: configuration file path can be vary depending on the Linux flavor as listed below)

 

# ifconfig eth0 192.168.2.10 netmask 255.255.255.0 up

 

(eth0 is a 1st network card adapter interface. eg. eth0, eth1 (2nd NIC), lo (loopback. UP is to bring up the interface, alternative, #ifup eth0 (activate the inferface eth0, #ifdown eth0 (reactive the interface eth0).

—————————–

route add -net 192.168.2.0 netmask 255.255.255.0 dev eth0(add a route to the network 192.168.2.x via “eth0”. The word “dev” can be omitted here)

# route add default gw 192.168.2.1 eth0

 Alternatively command
# route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1 dev eth0

 find . -name network

Your main network configuration file is /etc/network/interfaces (depends on Linux flavor)
#mii-tool or # ethtool eth0 ( check duplex and speed set on NIC)

_____________________________________________
Following commands are useful to find active ports and it’s assocated programs.

netstat –tcp –listening –programs
netstat –UDP –listening –programs
netstat -apnu (list UDP ports)
netstat -apnt (list TCP ports
netstat -nlp (list of tcp & UDP, domain sockets)

netstat –statistics –raw (display networkign statistics
Check online: http://webkeet.com/openportchecktool.aspx

nmap -sS -sU -T4 -A -v 192.168.2.10 (gui version of nmap – Zenmap: http://nmap.org/download.html)

Advertisements

About Robiul

Robiul has 15 years of continuous successful career experience in ICT with extensive background in System Engineering, IT infrastructure design, operations and service delivery, managing IT projects / MIS functions for local and multi-national companies with in-depth knowledge of multiple operating systems as well as construct / manage small to medium size Data Center. Proven ability to design and implement medium to semi-large scale LAN/WAN/WLAN and system infrastructures. Academic qualification: Master of Science in Information Systems. Professional certifications are: MCSE, CCNA, ITIL and FoundStone Security Professional, VCP, NetAPP, CISSP etc.
This entry was posted in Linux and tagged . Bookmark the permalink.