Find Out What Process is Listening on a Specific TCP Port

There are two commands which are popular to get the result: netstat and lsof. We probably already have been familiar with

netstat -nlp

to list all the listening ports. We actually could do

lsof -Pnl +M -i4

to list all IPv4 ports or

lsof -Pnl +M -i6

to list all IPv6 ports as well.

Static IP Configuration in CentOS

For example, to configure the IP of eth0, edit the file /etc/sysconfig/network-scripts/ifcfg-eth0

## Configure eth0
#
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
 
DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
HWADDR=A4:BA:DB:37:F1:04
NAME="System eth0"
TYPE=Ethernet
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
BOOTPROTO=static
IPADDR=192.168.1.88 # Replace with your ip address
NETMASK=255.255.255.0
 
 
## Configure Default Gateway
#
# vi /etc/sysconfig/network
 
NETWORKING=yes
HOSTNAME=centos6
GATEWAY=192.168.1.1

And then restart the network interfaces by

/etc/init.d/network restart

Optionally, configure the DNS servers by editing the file /etc/resolv.conf

## Configure DNS Server
#
# vi /etc/resolv.conf
 
nameserver 8.8.8.8 # Replace with your nameserver ip
nameserver 192.168.1.1 # Replace with your nameserver ip

Reset iptables / Clear / Remove all iptables rules

iptables has many different tables. In order to reset it or remove all rules of it, you need to run a series of commands like below:

iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -t raw -F
iptables -t raw -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

Don’t forget to save your iptables configuration. However, you have another option to do it easily and permanently by running the following command:

> /etc/sysconfig/iptables

And then restart the iptables service. All the rules will go away.

How to delete user password in Linux?

How do I delete user Password under Linux? I’d like to disable a password for an account.

After Google, I’ve found the solution.

All user encrypted passwords are stored in /etc/shadow file. The quick way to remove/delete a user password is pass –delete option to passwd command. First, login in as a root user.

Command to delete user password under Linux

Type the following command to delete a user password:

# passwd --delete username

OR

# passwd -d username

Above command delete a user’s password (make it empty). This is a quick way to disable a password for an account. It will set the named account passwordless. User will not able to login. It is also a good idea to setup user shell to nologin to avoid security related problems:

# usrmod -s /sbin/nologin username

For example to delete password for user vivo, Type:

# passwd -d vivo
# usrmod -s /sbin/nologin vivo