How to Change DHCP to Static IP Address on Fedora Using the Command Line
Introduction:
In this tutorial, we will walk you through the process of changing your network configuration from DHCP (Dynamic Host Configuration Protocol) to a Static IP address on a Fedora-based Linux system using the command line. Switching to a static IP address can be useful for various reasons, such as setting up a server, ensuring a consistent IP for networked devices, or troubleshooting network issues. Follow these steps carefully to configure a static IP address on your Fedora system.
**Prerequisites:**
- A Fedora-based Linux system (such as Fedora Workstation)
- Administrative privileges (you may need to use `sudo`)
**Step 1: Open Terminal**
Open a terminal window on your Fedora system. You can do this by searching for "Terminal" in your applications or using the keyboard shortcut `Ctrl+Alt+T`.
**Step 2: Check Current Network Configuration**
Before making changes, it's a good practice to check your current network configuration. Use the following command to view your network settings:
```bash
ip addr show
```
Look for the network interface you want to configure with a static IP address. Typically, it's named something like `eth0` or `enp0s3`.
**Step 3: Backup Existing Configuration (Optional)**
It's always a good idea to back up your existing network configuration files before making changes. You can do this using the `cp` command:
```bash
sudo cp /etc/sysconfig/network-scripts/ifcfg-your-interface-name /etc/sysconfig/network-scripts/ifcfg-your-interface-name.backup
```
Replace `your-interface-name` with the actual name of your network interface.
**Step 4: Edit the Network Configuration File**
Next, open the network configuration file for editing using your preferred text editor. In this example, we'll use `nano`, but you can use `vi`, `gedit`, or any other text editor:
```bash
sudo nano /etc/sysconfig/network-scripts/ifcfg-your-interface-name
```
Replace `your-interface-name` with the name of your network interface.
**Step 5: Configure the Static IP Address**
Inside the configuration file, you should see lines similar to this:
```bash
BOOTPROTO=dhcp
```
Change `dhcp` to `static`:
```bash
BOOTPROTO=static
```
Now, add the following lines to set your desired static IP address, subnet mask, gateway, and DNS servers. Replace the placeholders with your specific network configuration:
```bash
IPADDR=your-static-ip-address
NETMASK=your-subnet-mask
GATEWAY=your-gateway-ip-address
DNS1=your-dns-server-1
DNS2=your-dns-server-2
```
**Step 6: Save and Exit**
Save your changes and exit the text editor (in `nano`, press `Ctrl+O` to save and `Ctrl+X` to exit).
**Step 7: Restart the Network Service**
To apply the changes, restart the network service using the following command:
```bash
sudo systemctl restart network
```
**Step 8: Verify the Configuration**
To confirm that your static IP address is properly configured, run:
```bash
ip addr show your-interface-name
```
Replace `your-interface-name` with your actual network interface name. You should see your static IP address in the output.
**Conclusion**
Congratulations! You have successfully changed your Fedora system from DHCP to a static IP address using the command line. Your network settings should now persist across reboots, providing a stable and predictable IP address for your system.
Comments
Post a Comment