Share this page : facebooktwitterlinkedinmailfacebooktwitterlinkedinmail

lsmod: list a modules that are currently loaded

rmmod: remove a module from the Linux kernel

Configure network interface:

 

Syntax:  ifconfig eth_name ip_address netmask network_mask broadcast broadcast address

eg. ifconfig eth0 192.168.0.23 netmask 255.255.255.0 broadcast 192.168.0.255

Use dhcp: dhclient

check the ip address and mask of an interface: ifconfig or netstat -i

Fedora add the info to /etc/sysconfig/network-script/ifcfg-interfacename

Ubuntu in the /etc/network/interfaces file.

To get the ipaddress from the DHCP: use the line “iface eth0 inet dhcp”

Use static : iface eth0 inet static , then add another line use format like:

address 192.168.0.23

netmask 255.255.255.0

gateway 192.168.0.1

Then use ifdown eth0 , then ifup eth0 to load the configuration file.

ipv6

how to disable IPv6 on Red Hat- and Debian-based distributions.

Here’s how to disable the protocol on a Red Hat-based system:

Open a terminal window.
Change to the root user.
Issue the command sysctl -w net.ipv6.conf.all.disable_ipv6=1
Issue the command sysctl -w net.ipv6.conf.default.disable_ipv6=1

To re-enable IPv6, issue the following commands:

sysctl -w net.ipv6.conf.all.disable_ipv6=0

sysctl -w net.ipv6.conf.default.disable_ipv6=0

DNS

Host file (cache): /etc/hosts

add DNS server into your system: /etc/resolv.conf file.  older Linux, the /etc/host.conf file used.

This file can contain up to 3 DNS servers.

If you require DNS for your temporary network configuration, you can add DNS server IP addresses in the file /etc/resolv.conf. In general, editing /etc/resolv.conf directly is not recommended, but this is a temporary and non-persistent configuration. The example below shows how to enter two DNS servers to /etc/resolv.conf, which should be changed to servers appropriate for your network.

The format is like:

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

A more proper persistent way to do DNS client configuration is in a following section.

nameserver 8.8.8.8

Dig

Stands for Domain Information groper, Dis is an excellent tool to do an DNS query .

basic command is like:

Dig www.google.com

For more complex use, check here:

 

Routing

To see the route table, use route command, or netstat -r command.

Enable routing ( IP forwarding ):

change the value in the file /proc/sys/net/ipv4/ip_forward into 1:

echo 1 > /proc/sys/net/ipv4/ip_forward

IPv4 routing at every boot,ensure that the line net.ipv4.ip_forward = 1 exists in the /etc/sysctl.conf file.

Add a route:

route add -net network_address netmask network_mask gw gateway_address

eg. route add -net 10.0.1.0 netmask 255.255.255.0 gw 10.0.1.1

OR

ip route add network_address/mask_length via gateway_addgess

eg. ip route add 10.0.1.0/24 via 10.0.1.1

delete a route:

route del network_address

Network services

Ports and their associated protocols are defined in the /etc/services file.

To see which port the telnet daemon listens, use grep telnet /etc/services

Ports range in number from 0 to 65534. The ports 0–1023 are called well-known ports.

Two kinds of network daemons:

  • Stand-alone daemons: Daemons that provide the network services directly.
  • Smaller network daemons: connections are started and managed by the inetd or xinetd daemons, which starts the appropriate daemon inorder to provide the network service as needed.
    • inetd ( Internet Super Daemon)
    • xinetd ( Extended Internet Super Daemon.
Network state

we can check the network state with netstat command:

The most common switches include:

(1) show network interface info:

#netstat –i

(2) show the active internet connections and socket of the server:

#netstat –lpe

Include the Program name, PID, I-node.

(3) show routing table info

#netstat –r

#netstat –nr

(4) show tcp or udp connection info:

#netstat –t

#netstat –u

Remote administration

Telnet : By default Root user is prevented from logging in and obtaining a shell, to enable this. Removing or renaming the file /etc/securetty.

SSH:

encrypt the information that passes between computers.

syntax: ssh -l username IP_address(or url)

First time to use SSH: Accept the RSA encryption fingerprint, which is stored in ~/.ssh/know_hosts

If the target computer’s encryption keys are regenerated, you will need to remove the old key from the ~/.ssh/known_hosts file before you connect again.

The –X option to the ssh command can be used to tunnel X Windows information through the SSH connection.

sshd is usually configured to allow  root logins and a wide range of encryption algorithms by default. However,you can configure the functionality of sshd by editing the /etc/ssh/sshd_config file.

File download

Under command line, the most popular download tools are wget and curl.

wget

The result is a single index.html file. On its own this file is fairly useless as the content is still pulled from Google and the images and stylesheets are still all held on Google.

To download the full site and all the pages you can use the following command:

wget -r www.everydaylinuxuser.com

This downloads the pages recursively up to a maximum of 5 levels deep.

5 levels deep might not be enough to get everything from the site. You can use the -l switch to set the number of levels you wish to go to as follows:

wget -r -l5 www.everydaylinuxuser.com

If you want infinite recursion you can use the following:

wget -r -l inf www.everydaylinuxuser.com

You can also replace the inf with 0 which means the same thing.

 

Send Mail from command

First of all, check if the /bin/mailx or /usr/bin/mailx  file exist or not. Or else, you need to install it:

# ubuntu/debian
$ sudo apt-get install heirloom-mailx

# fedora/centos
$ sudo yum install mailx
Simple mail

Run the following command, and then mailx would wait for you to enter the message of the email. You can hit enter for new lines. When done typing the message, press Ctrl+D and mailx would display EOT.

After than mailx automatically delivers the email to the destination.

$ /bin/mail -s "Subject" [email protected]
Hi!
How are you
I am fine
Bye
[ctrl+D to send]
EOT
Use SMTP

echo ” The mail body” | mailx -v -r “[email protected]” -s “Test Message” -S smtp=”smtp.smtp_server_domain.com:port” -S smtp-auth=plain -S smtp-auth-user=”sender” -S smtp-auth-password=”xxxxx” [email protected]_domain.com

  • -v : show the process verbosely
  • -r: sender email
  • -s: title
  • -S: parameters
Specify “Reply-To” address

The reply to address is set with the internal option variable “replyto” using the “-S” option.

# replyto email
$ echo "This is message" | mail -s "Testing replyto" -S replyto="[email protected]" [email protected]

# replyto email with a name
$ echo "This is message" | mail -s "Testing replyto" -S replyto="Mark<[email protected]>" [email protected]
Attachments

Attachments can be added with the “-a” option.

$ echo "This is message body" | mail -s "This is Subject" -r "Harry<[email protected]>" -a /path/to/file [email protected]

For more use, check here:

9 mail/mailx command examples to send emails from command line on Linux

Reference

Mailx: http://heirloom.sourceforge.net/mailx/mailx.1.html

Related pages: