Sign In
Sign In

How to Configure an Additional IP as an Alias in Ubuntu

How to Configure an Additional IP as an Alias in Ubuntu
Adnene Mabrouk
Technical writer
Ubuntu
29.11.2024
Reading time: 6 min

In the network administration world, the task of setting up additional IP addresses on a single network interface is commonly performed. The technique of IP aliasing, which is a system for a device to reply to several IP addresses on one network interface, penetrates this model. All Ubuntu users should be familiar with modifying and applying these settings to ensure robust networking administration.

This guide will detail the methods of creating an extra IP address in Ubuntu as an alias for both the versions of Ubuntu 24.04 and 22.04.

Prerequisites

Obviously, one first needs to set up the system in a way that would allow for the manipulation of all IP addresses over the same network, using Ubuntu. Here is the list:

  • A system running either Ubuntu 24.04 or Ubuntu 22.04
  • Admin access to the system (sudo privileges)
  • Basic knowledge of command-line interface operations
  • An additional IP address assigned by a network administrator or ISP
  • Network interface name information (e.g., eth0, ens3)

When troubleshooting problems, we are in danger of causing even more difficulty, as network interfaces provided by networks are not reliable. With this in mind, it would be wise to keep a backup of the configuration files before proceeding with the changes.

Configuring an Additional IP Address within Ubuntu 24.04

Ubuntu 24.04, the latest long-term support release, uses Netplan for network configuration. This configuration is also applicable for Ubuntu 22.04 and beyond.

Netplan is a utility for configuring networking on Linux systems. Here's how to create an additional IP address:

  1. Check the Network Interface

Primarily, it is necessary to define the network interface that will carry the new address. You can achieve this by running the following command:

ip addr show

The output of this command will display all the interfaces. Find the name of the interface (e.g. ens3, eth0) currently in use.

  1. Edit the Netplan Configuration File

Normally Netplan configuration files are found in the /etc/netplan/ directory. The file name may be different but most of them end with a .yaml extension. To change the file, use a text editor with root privileges:

sudo nano /etc/netplan/50-cloud-init.yaml
  1. Insert the New IP Address

In the YAML file, add the new IP address under the addresses section of the appropriate network interface. The configuration may appear like this:

network:
  version: 2
  renderer: networkd
  ethernets:
	eth0:
  	  addresses:
  	  - "195.133.93.70/24"
  	  - "166.1.227.189/24" #New IP address
  	  - "192.168.1.2/24" #Private IP address
  	nameservers:
    	  addresses:
    	  - "1.1.1.1"
    	  - "1.0.0.1"
  	dhcp4: false
  	dhcp6: false
  	routes:
  	- to: "0.0.0.0/0"
        via: "195.133.93.1"
  1. Apply the Changes

Upon saving your edits, you need to apply the new version of the configuration by running this command:

sudo netplan apply
  1. Validate the Configuration

After completing the steps above, you will need to repeat the ip addr show command to confirm that the new IP address is in place. Now the output of this command should also include the new IP address.

Additional Considerations

  • Persistent Configuration

The choices made by Netplan are stable and will last through the restart of the device. But, it's a good idea to verify the configuration with a system reboot to make sure everything goes well after the restart.

  • Firewall Configuration

When adding a new IP address, you may need to update the firewall rules. Ubuntu traditionally uses UFW (Uncomplicated Firewall). To avoid blocking the new IP, you will have to create new rules to UFW.

  • Network Services

If the system has some services running which are linked to specific IP addresses, then you must update their configurations to recognize and utilize the new IP address as well.

  • IPv6 Considerations

The above examples talk about IPv4. If you have to use IPv6 addresses, then the procedure is relatively the same; you will have to use a different style of address though. Netplan supports both IPv4 and IPv6 configurations.

Troubleshooting

In case of issues emerging during the configuration stage, try:

  • Check for syntax errors in the YAML file with the command: sudo netplan --debug generate.
  • Ensure that there are no conflicts with other devices using the same IP address on the network.
  • Verify correct setting of the subnet mask and the gateway.
  • Check the system logfile for error messages: journalctl -xe.

Advanced IP Aliasing Techniques

Network administrators can see how advanced IP aliasing plays a key role in improving network management: virtual interfaces make it possible to have several logical interfaces on a physical network interface, wherein all have their IP and network settings.

  • Dynamic IP Aliasing

There are cases where network administrators would have to implement dynamic IP aliasing. With the help of scripts, it is possible to add or remove IP aliases according to certain conditions or occurrences. For example, a script can be made to insert an IP alias whenever a particular service starts and remove it every time the service stops.

  • IP Aliasing in Containerized Environments

The popularity of containerization in the present age necessitates having IP aliasing in order to control network configuration of Docker containers and any other containerized applications. In such cases, IP aliases are quite often employed to expose multiple services on a container at different IP addresses or assist containers to communicate with one another.

  • Docker Network Aliases

In Docker, network aliases can be used to allow multiple containers to respond to the same DNS name on a custom network. Among other things, this is indispensable in microservices architectures where service discovery is a very important issue.

Security Implications of IP Aliasing

Though IP aliasing has a multitude of advantages, the issue of security deserves also to be looked into. Among other things, the more IP addresses you put, the larger the possible security breach of a system. The network administrators must guarantee the applications are protected with:

  • Configurations of a firewall that will secure all the IP aliases
  • Intrusion Detection Systems (IDS) to record the traffic of all IP addresses
  • Periodically checking the use and need of each IP alias
  • Enabling of appropriate security tools for those services bound to specific IP aliases

Conclusion

Putting a new IP address as an alias into Ubuntu is a highly efficient process as their utility of Netplan helps greatly. Whether you are using Ubuntu 24.04 or 22.04, the steps remain the same including editing the Netplan configuration file, adding the new IP address, and applying the changes. A system with multiple IP addresses on a single network interface of a single computer can be used to do different tasks on such a network. The ability to respond to several IP addresses on one network interface becomes very useful in several networking situations.

Through these steps, you can increase the Ubuntu computer networking capabilities quickly and effectively. The sequence is always to first back up existing configurations then to make changes followed by in-depth test post-installation. With these skills, a network infrastructure manager or an IT technician can effectively manage and optimize his Ubuntu-powered network infrastructure to cater to diverse networking requirements.

Ubuntu
29.11.2024
Reading time: 6 min

Similar

PHP

Installing and Switching PHP Versions on Ubuntu: A Step-by-Step Guide

PHP is a scripting programming language commonly used for developing web applications. It allows developers to create dynamic websites that adapt their pages for specific users. These websites are not stored on the server in a ready-made form but are created on the server after a user request. This means that PHP is a server-side language, meaning scripts written in PHP run on the server, not the user's computer. There are many different versions of PHP. The language becomes more powerful and flexible with each new version, offering developers more opportunities to create modern web applications. However, not all websites upgrade or are ready to upgrade to the latest PHP version and remain on older versions. Therefore, switching between versions is an essential task for many web developers. Some developers want to take advantage of new features introduced in newer versions, while others need to fix bugs and improve the security of existing applications. In this article, we will go over how to install PHP on Ubuntu and how to manage different PHP versions. How to Install PHP on the Server To install PHP on Ubuntu Server, follow these steps: Connect to the server via SSH. Update the package list: sudo apt update Install the required dependencies: sudo apt install build-essential libssl-dev Download the installation script from the official website, replacing <version> with the desired version: curl -L -O https://www.php.net/distributions/php-<version>.tar.gz Extract the downloaded file, replacing <version> with the downloaded version: tar xzf php-<version>.tar.gz Navigate to the directory with the installed PHP: cd php-<version> Configure the installation script: ./configure Build PHP: make Install PHP: sudo make install After completing these steps, PHP will be installed on your server. The next step is to install a web server to work with PHP. The configuration may involve specifying the PHP module in the web server configuration file and setting up how .php files are handled. Finally, restart the web server. For example, to restart Apache, you can run the following command: sudo service apache2 restart How to Check PHP Version There are several ways to find out which version of PHP a website is running: Use the terminal. Create a script with phpinfo() in the website's root directory. Check PHP Version via Terminal Run the command in the terminal: php -v You will get output similar to: PHP 8.3.13 (cli) (built: Oct 30 2024 11:27:41) (NTS)Copyright (c) The PHP GroupZend Engine v4.3.13, Copyright (c) Zend Technologies    with Zend OPcache v8.3.13, Copyright (c), by Zend Technologies Check PHP Version with phpinfo() Create a file named phpinfo.php with the following content: <?phpphpinfo( );?> Save the file in the root directory of your website (where the index.html or index.php file is located). Open this file in your browser by using the following URL: http://your_website_address/phpinfo.php You will see a page with detailed information about the PHP configuration. After finding out the PHP version, be sure to delete the phpinfo.php file as it contains important server configuration information that attackers could exploit. How to Manage PHP Versions To switch between installed PHP versions on Ubuntu, follow these steps. Check if multiple PHP versions are installed. To see the list of installed PHP packages, run the command: dpkg --list | grep php Install the php-switch package, which allows change PHP versions easily: sudo apt-get install -y php-switch Switch to the desired PHP version using the php-switch command. For example, to switch to PHP 7.4, run: php-switch 8.2 Verify which PHP version is currently active by running: php -v Some scripts and extensions may only work with certain PHP versions. Before switching, make sure that all the scripts and extensions you are using support the new version. Otherwise, the website may become inaccessible or malfunction. Troubleshooting If PHP scripts are not being processed on your server, the first thing to check is the web server's functionality. Open a browser and go to the website where PHP scripts are not working. If the page opens but the PHP script output is not displayed, the problem may lie with PHP. Here are some steps you can take to troubleshoot the issue. Check PHP Service Status Run the following command, using your PHP version (e.g., PHP 8.3): sudo service php8.3-fpm status If the service is running, the output should indicate active (running). If the service is not running, start it with this command: sudo service php8.3-fpm start Check PHP Log Files To view PHP log files, use the following command: tail /var/log/php7\8.3-fpm.log This command will display the last few lines of the PHP log file, which may help identify the issue. Check PHP Configuration Open the php.ini file in a text editor and ensure the display_errors option is set to On. This will allow PHP errors to be displayed on your website pages. Check for Script Errors Open the PHP scripts in a text editor and look for syntax errors or other issues that could prevent the scripts from working properly. Check for Web Server Restrictions Check the web server configuration for any restrictions that might affect the execution of PHP scripts. For example, there may be restrictions in the .htaccess file that prevent certain directories from running scripts. Test the Script on Another Server If the script works on another server, the issue may be related to the configuration of the current server.
20 November 2024 · 5 min to read
Ubuntu

How to Install VNC on Ubuntu

If you need to interact with a remote server through a graphical interface, you can use VNC technology.VNC (Virtual Network Computing) allows users to establish a remote connection to a server over a network. It operates on a client-server architecture and uses the RFB protocol to transmit screen images and input data from various devices (such as keyboards or mice). VNC supports multiple operating systems, including Ubuntu, Windows, macOS, and others. Another advantage of VNC is that it allows multiple users to connect simultaneously, which can be useful for collaborative work on projects or training sessions. In this guide, we will describe how to install VNC on Ubuntu, using a Hostman cloud server with Ubuntu 22.04 as an example. Step 1: Preparing to Install VNC Before starting the installation process on both the server and the local machine, there are a few prerequisites to review.  Here is a list of what you’ll need to complete the installation: A Server Running Ubuntu 22.04. In this guide, we will use a cloud server from Hostman with minimal hardware configuration. A User with sudo Privileges. You should perform the installation as a regular user with administrative privileges. Select a Graphical Interface. You’ll need to choose a desktop environment that you will use to interact with the remote server after installing the system on both the server and the local machine. A Computer with a VNC Client Installed.  Currently, the only way to communicate with a rented server running Ubuntu 22.04 is through the console. To enable remote management via a graphical interface, you’ll need to install a desktop environment along with VNC on the server. Below are lists of available VNC servers and desktop environments that can be installed on an Ubuntu server. VNC Servers: TightVNC Server. One of the most popular VNC servers for Ubuntu. It is easy to set up and offers good performance. RealVNC Server. RealVNC provides a commercial solution for remote access to servers across various Linux distributions, including Ubuntu, Debian, Fedora, Arch Linux, and others. Desktop Environments: Xfce. A lightweight and fast desktop environment, ideal for remote sessions over VNC. It uses fewer resources than heavier desktop environments, making it an excellent choice for servers and virtual machines. GNOME. The default Ubuntu desktop environment, offering a modern and user-friendly interface. It can be used with VNC but will consume more resources than Xfce. KDE Plasma. Another popular desktop environment that provides a wide range of features and a beautiful design. The choice of VNC server and desktop environment depends on the user’s specific needs and available resources. TightVNC and Xfce are excellent options for stable remote sessions on Ubuntu, as they do not require high resources. In the next step, we will describe how to install them on the server in detail. Step 2: Installing the Desktop Environment and VNC Server To install the VNC server on Ubuntu along with the desktop environment, connect to the server and log in as a regular user with administrative rights. Update the Package List  After logging into the server, run the following command to update the packages from the connected repositories: sudo apt update Install the Desktop Environment  Next, install the previously selected desktop environment. To install Xfce, enter: sudo apt install xfce4 xfce4-goodies Here, the first package provides the basic Xfce desktop environment, while the second includes additional applications and plugins for Xfce, which are optional. Install the TightVNC Server  To install TightVNC, enter: sudo apt install tightvncserver Start the VNC Server  Once the installation is complete, initialize the VNC server by typing: vncserver This command creates a new VNC session with a specific session number, such as :1 for the first session, :2 for the second, and so on. This session number corresponds to a display port (for example, port 5901 corresponds to :1). This allows multiple VNC sessions to run on the same machine, each using a different display port. During the first-time setup, this command will prompt you to set a password, which will be required for users to connect to the server’s graphical interface. Set the View-Only Password (Optional)  After setting the main password, you’ll be prompted to set a password for view-only mode. View-only mode allows users to view the remote desktop without making any changes, which is helpful for demonstrations or when limited access is needed. If you need to change the passwords set above, use the following command: vncpasswd Now you have a VNC session. In the next step, we will set up VNC to launch the Ubuntu server with the installed desktop environment. Step 3: Configuring the VNC Server The VNC server needs to know which desktop environment it should connect to. To set this up, we’ll need to edit a specific configuration file. Stop Active VNC Instances  Before making any configurations, stop any active VNC server instances. In this guide, we’ll stop the instance running on display port 5901. To do this, enter: vncserver -kill :1 Here, :1 is the session number associated with display port 5901, which we want to stop. Create a Backup of the Configuration File  Before editing, it’s a good idea to back up the original configuration file. Run: mv ~/.vnc/xstartup ~/.vnc/xstartup.bak Edit the Configuration File  Now, open the configuration file in a text editor: nano ~/.vnc/xstartup Replace the contents with the following: #!/bin/bashxrdb $HOME/.Xresourcesstartxfce4 & #!/bin/bash – This line is called a "shebang," and it specifies that the script should be executed using the Bash shell. xrdb $HOME/.Xresources – This line reads settings from the .Xresources file, where desktop preferences like colors, fonts, cursors, and keyboard options are stored. startxfce4 & – This line starts the Xfce desktop environment on the server. Make the Configuration File Executable To allow the configuration file to be executed, use: chmod +x ~/.vnc/xstartup Start the VNC Server with Localhost Restriction Now that the configuration is updated, start the VNC server with the following command: vncserver -localhost The -localhost option restricts connections to the VNC server to the local host (the server itself), preventing remote connections from other machines. You will still be able to connect from your computer, as we’ll set up an SSH tunnel between it and the server. These connections will also be treated as local by the VNC server. The VNC server configuration is now complete. Step 4: Installing the VNC Client and Connecting to the Server Now, let’s proceed with installing a VNC client. In this example, we’ll install the client on a Windows 11 computer. Several VNC clients support different operating systems. Here are a few options:  RealVNC Viewer. The official client from RealVNC, compatible with Windows, macOS, and Linux. TightVNC Viewer. A free and straightforward VNC client that supports Windows and Linux. UltraVNC. Another free VNC client for Windows with advanced remote management features. For this guide, we’ll use the free TightVNC Viewer. Download and Install TightVNC Viewer Visit the official TightVNC website, download the installer, and run it. In the installation window, click Next and accept the license agreement. Then, select the custom installation mode and disable the VNC server installation, as shown in the image below. Click Next twice and complete the installation of the VNC client on your local machine. Set Up an SSH Tunnel for Secure Connection To encrypt your remote access to the VNC server, use SSH to create a secure tunnel. On your Windows 11 computer, open PowerShell and enter the following command: ssh -L 56789:localhost:5901 -C -N -l username server_IP_address Make sure that OpenSSH is installed on your local machine; if not, refer to Microsoft’s documentation to install it. This command configures an SSH tunnel that forwards the connection from your local computer to the remote server over a secure connection, making VNC believe the connection originates from the server itself. Here’s a breakdown of the flags used: -L sets up SSH port forwarding, redirecting the local computer’s port to the specified host and server port. Here, we choose port 56789 because it is not bound to any service. -C enables compression of data before transmitting over SSH. -N tells SSH not to execute any commands after establishing the connection. -l specifies the username for connecting to the server. Connect with TightVNC Viewer After creating the SSH tunnel, open the TightVNC Viewer and enter the following in the connection field: localhost:56789 You’ll be prompted to enter the password created during the initial setup of the VNC server. Once you enter the password, you’ll be connected to the VNC server, and the Xfce desktop environment should appear. Stop the SSH Tunnel To close the SSH tunnel, return to the PowerShell or command line on your local computer and press CTRL+C. Conclusion This guide has walked you through the step-by-step process of setting up VNC on Ubuntu 22.04. We used TightVNC Server as the VNC server, TightVNC Viewer as the client, and Xfce as the desktop environment for user interaction with the server. We hope that using VNC technology helps streamline your server administration, making the process easier and more efficient.
15 November 2024 · 8 min to read
Ubuntu

How To Install Webmin on Ubuntu 24.04

Managing a Linux server can be challenging, particularly when dealing with standard duties like system monitoring, service configuration, and user administration. Despite its strength, command-line management necessitates knowledge of Linux commands and setups, which might be difficult for novice admins. Webmin offers a solution that simplifies these tasks and makes server management possible even for people without a lot of Linux experience thanks to its intuitive, web-based user interface. This article offers a thorough, step-by-step tutorial that starts with the required package updates and progresses through the installation of dependencies, repository settings, and secure access setup. Every component has been thoughtfully created to guarantee that customers fully comprehend the installation procedure as well as the security issues at play.. After the successful installation of Webmin, a versatile and user-friendly tool will be available to readers to manage their Ubuntu server directly from a web browser. Webmin gives users the ability to easily and effectively utilize critical server administration activities, such as setting up network services, creating and maintaining user accounts, and keeping an eye on system health. Even with little knowledge of Linux command-line interfaces, users may confidently manage servers by following this guide, which will enable users to make the most of the Linux environment. Prerequisites The requirements to install Webmin on Ubuntu 24.04 are as follows: A local computer or a cloud server with Ubuntu 24.04 installed A regular user with sudo access. Since installing Webmin requires downloading packages from external repositories, make sure the server has access to the internet. Make a new DNS record with a subdomain that points to the IP address of the server that hosts it. Take mywebmin.mydomain.com, for instance. Install Webmin Here are the step-by-step instructions for installing Webmin on Ubuntu 24.04. It is advised to upgrade any outdated packages and update the system's package lists first. This guarantees a trouble-free installation of Webmin and its dependencies. Execute the subsequent commands: sudo apt update && sudo apt upgrade -y Add Webmin repository. Users must manually add the Webmin repository because it is not part of the official Ubuntu repositories. Get the Webmin repository's GPG key by running the command below. wget -qO - http://www.webmin.com/jcameron-key.asc | sudo apt-key add - Include the Webmin repository to the system’s sources list. sudo sh -c 'echo "deb http://download.webmin.com/download/repository sarge contrib" > /etc/apt/sources.list.d/webmin.list' To establish the newly added repository, refresh the package list after adding it. sudo apt update Install Webmin now using: sudo apt install webmin -y After installation is finished, you can use a web browser to access Webmin. Open the web browser and navigate to this page: http://<server-ip>:10000 In our case, the IP address is 166.1.227.224: http://166.1.227.224:10000 Secure Webmin Update the SSL Webmin configuration. For encrypted connections, Webmin uses SSL by default; however, users must confirm this configuration. Open the Webmin configuration file in order to verify or enable SSL. Run the command below. sudo nano /etc/webmin/miniserv.conf Search the line with port=10000 and change it to another port. For example: Save your modifications and restart Webmin. sudo systemctl restart webmin Restricting access to specific IP addresses improves security by restricting the devices that can access Webmin. In order to view or change the allowed IPs, open the Webmin startup file and run the command below. sudo nano /etc/webmin/miniserv.conf In order to include only trusted IP addresses, change the allow= line. If it doesn’t exist yet, add it. allow=your_trusted_ip The actual IP address should be substituted for your_trusted_ip. One can add more than one address, with spaces between them. Restart Webmin after saving the file. sudo systemctl restart webmin Set Up Firewall Rules If a firewall is present, configure it; Webmin uses port 10000 by default. If the system has a firewall installed, such as UFW, grant Webmin access with the following steps. Check Firewall Status First, confirm that the UFW firewall is active. Run the following command to view the current status. sudo ufw status If the firewall isn't yet activated, use the command ufw enable to turn it on., but make sure to allow SSH service first to prevent the current session from terminating and being able to SSH to the server again. To allow the SSH service, run the following command.  sudo ufw allow ssh Run the following command to activate the firewall.  sudo ufw enable By default, Webmin uses port 10000. To allow traffic on this port, use the following command. sudo ufw allow 10000/tcp If Webmin is configured to use a custom port, try using a different port number instead of 10000. Grant access, for example, by using the following command  if Webmin is to set up on port 22000. sudo ufw allow 22000/tcp Limit Individual IP addresses' access. Increase Webmin's security by configuring the firewall to only allow access from specific, verified IP addresses. To limit access to 192.168.1.100, for example, run the command below. sudo ufw allow from 192.168.1.100 to any port 10000 proto tcp Repeat this command for each additional IP address that requires access. To ensure that the changes take effect when the rules are specified, reload UFW by running the following command. sudo ufw reload Check the firewall's status once again to ensure that the rules are in place. sudo ufw status Access Webmin Launch any current web browser, such Edge, Firefox, or Chromeweb, to access the Webmin interface after installing Webmin and setting up firewall rules. Enter the IP address of the server in the address bar, then Webmin's port (10000 by default or your custom port if you reconfigured): https:/<server-ip>/:10000. For example: https://166.1.227.224:10000 Because Webmin's default SSL certificate is self-signed, the browser can show a security warning if it is applied. Users should choose "Accept the Risk" or "Proceed to Site" in order to continue to Webmin. Enter the root username and password of the server, or any other account with sudo rights, to access the dashboard once the Webmin login screen is displayed. After successfully logging in, users will be taken to the Webmin dashboard, where they may manage users, monitor services, adjust settings, access a variety of system administration tools, and perform any other tasks related to administration on the Ubuntu server. Conclusion In conclusion, setting up Webmin on Ubuntu 24.04 offers a stable, intuitive interface for handling server responsibilities, enabling system management to be used by both inexperienced and seasoned users. Users may easily install, secure, and use Webmin by following this guide. This gives them the power to manage users, services, firewall settings, and more from a single online interface. By enabling administrators to carry out necessary operations in a convenient and efficient manner, Webmin improves server management efficiency and security.
14 November 2024 · 6 min to read

Do you have questions,
comments, or concerns?

Our professionals are available to assist you at any moment,
whether you need help or are just unsure of where to start.
Email us
Hostman's Support