httpd: (98)Address already in use

After configuring an Apache server on a CentOS 7.5 server, I tried to start the service but I got this error in return:

systemd[1]: Starting The Apache HTTP Server...
httpd[47662]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:443
systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE

I was pretty sure that nothing was using port 443 but I did a quick check with netstat -tulpn

I double checked my config files, just to be sure that I wasn’t declaring Listen 443 twice:

# grep -ir listen
conf/httpd.conf:Listen 80
conf.d/ssl.conf:# When we also provide SSL we have to listen to the
conf.d/ssl.conf:Listen 443 https
conf.d/custom.conf:Listen 443

That’s it! I forgot to comment the directive in ssl.conf file (in this case). After this tiny fix I was able to start httpd without errors.

Adding a secondary IP address (CentOS, Fedora, RHEL)

You will not need a secondary NIC but you’ll create virtual adapters as the secondary IP will be routing through the primary.

Network configurations are stored in /etc/sysconfig/network-scripts

network-scripts$ ls -l | grep ifcfg
-rw-r--r--. 1 root root 304 Nov 11 19:04 ifcfg-eth0
-rw-r--r--. 1 root root 254 May 25 2017 ifcfg-lo

You have to name the virtual adapter in a sequential order, e.g., ifcfg-eth0:1, ifcfg-eth0:2 etc.

Copy the physical adapter configuration file:

cp ifcfg-eth0 ifcfg-eth0:1

and configure it to include these parameters:

DEVICE=<device name>
IPADDR=<IP address>
NETMASK=<netmask>

There is no need to configure a MAC address or a default gateway.

To activate the interface you can restart the entire network server (if you can do it) or use:

ifup eth0:1

Flushing iptables

You can flush and reset iptables to default running these commands:

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

The -F command flushes all the chains and -X deletes empty (non-default) chains.
You can also create a script:Continue reading

Using sudo without password

When you issue a sudo command you will be asked to type your password to execute it and this can be quite annoying, especially for people like me that open the terminal every 3 minutes and don’t want to login as root every time.

To solve this “problem” you need to edit sudo’s configuration file, located in /etc/sudoers, but it’s not recommended to do it directly. To modify this file, you have to use visudo that makes a temporary copy of the sudoers file and checks for errors before saving.Continue reading