Fedora 17: Setting a static IP address

Fedora Bash
This is a quick tutorial on how to set a static IP address using the terminal within Fedora 17.

note: these instructions also work in Fedora 18.

Disable Network Manager

1. First stop and disable the gnome network manager from running on boot.

systemctl stop NetworkManager.service
systemctl disable NetworkManager.service

2. Now start and enable the network service to run on boot.

systemctl restart network.service
systemctl enable network.service

Set the Static Address

1. Check which interface(s) you want to set as static.

[root@server ~]# ifconfig
em1: flags=4163 mtu 1500
inet 192.168.1.148 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::dad3:85ff:feae:dd4c prefixlen 64 scopeid 0x20 ether d8:d3:85:ae:dd:4c txqueuelen 1000 (Ethernet)
RX packets 929 bytes 90374 (88.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1010 bytes 130252 (127.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 19

lo: flags=73mtu 16436
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 0 (Local Loopback)
RX packets 32 bytes 3210 (3.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 32 bytes 3210 (3.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

2. Next edit the config file for the required interface.

vi /etc/sysconfig/network-scripts/ifcfg-em1

3. Edit the config file to look similar to the following.

Change the BOOTPROTO from “dhcp” to “static”. Also adding IPADDR, NETMASK, BROADCAST and NETWORK variables and make sure ONBOOT is set to yes.

UUID="e88f1292-1f87-4576-97aa-bb8b2be34bd3"
NM_CONTROLLED="yes"
HWADDR="D8:D3:85:AE:DD:4C"
BOOTPROTO="static"
DEVICE="em1"
ONBOOT="yes"
IPADDR=192.168.1.2
NETMASK=255.255.255.0
BROADCAST=192.168.1.255
NETWORK=192.168.1.0
GATEWAY=192.168.1.1

Apply the Settings

Restart the network service to apply the settings.

systemctl restart network.service

Configure DNS

Make sure the correct DNS servers are configured to allow Fedora to resolve domains.

vi /etc/resolv.conf
nameserver 192.168.1.1
nameserver 8.8.8.8
  • Arun

    Hi Daniel,

    I managed to set my Fedora 17 to a static IP following the above post.
    Firefox does not connect to the internet though. Can you help me resolve that?

    Thanks,
    Arun

    • http://danielgibbs.co.uk dgibbs

      It could be your proxy settings in Firefox. Make sure they are set to auto detect. Also check your details are correct like your default gateway. Try to ping google.com and 8.8.8.8 to check that DNS is working and the internet is general. Hope this helps

      • fab

        Hi Daniel,

        I have the same problem too..firefox doesn´t connect to the internet anymore. Do you know where to change the proxy settings on firefox? I tried to find Tool/options on the defaul version but i couldn´t find it so i update my version on the terminal but i still don´t know where to chenge them.

        Do you have any suggestion?

        Thanks,
        Fabry

        • http://danielgibbs.co.uk Daniel Gibbs

          Tools>Options>Advanced>Network>Connection>Settings…

          Try ‘Auto-detect proxy settings’ for this network.

          Also try chrome. I have personally found Firefox to not work very well on Linux in general

          • http://www.comic234.com Godfroy

            This is nonsense. I am a programmer and I can tell you Firefox has nothing the hell to do with this problem . lol Try to give advices that are based on something more critical please. Firefox is one of the best internet flyer we got.

          • http://danielgibbs.co.uk Daniel Gibbs

            @Godfroy. I’m glad you programming skills somehow make you qualified to say my free advise is useless. If I need advise on C#, Java, php etc then i’m guessing your the person to ask. However I am a Linux and Windows Systems Engineer and work/configure this software to work on various size networks.

            Firstly if you have a better way please reply with a useful suggestion. Where I work we used to have several gateways and regularly had to change proxy’s in Firefox. Firefox manages its own proxy’s and doesn’t always use the one set by the system unlike chrome which uses the systems only. So its worth checking these settings to make sure ‘Auto detect’ is selected. If this fails I believe you can try ‘none’. Different networks may require different proxy settings.

            Yeah Firefox is great I have been using it since version 1.0. However i’m my personal experience using it on Ubuntu & Centos I have found chrome to perform better and crashes less than firefox.

            I cannot guarantee that my advise is always accurate or that it will work in an individuals circumstances but it might help.

          • andrew

            hi Daniel,

            I am having the same problem and nothing you suggested worked. What I did was disable the network service and enabled the genome but now I am back where I started. I am a super noob at this but I was able to follow your instructions.

            My question is why must we disable the genome?

            And can we change the IPADDR, NETMASK, BROADCAST and NETWORK variables to what ever we want?

            Thanks,
            andrew

          • http://danielgibbs.co.uk Daniel Gibbs

            Hello Andrew,

            I think you are referring to the network settings withing Gnome 3. You can set a static IP address via the GUI interface in Gnome and set a static address.

            This tutorial is more useful for someone who wants to use Fedora as a server or having issues with Gnome. If you are using Fedora as a desktop then sticking with the Gnome network manager may be a better choice for you

  • http://www.solrei.com Charles McGowen

    I need Network Manager to remain in control AND I need the static IP address. When I disable Network Manager critical files are deleted by systemctl with rm commands and the network interface dies all together. Presumably because configuration files elsewhere on the system go poof.

    I modify the /etc/sysconfig/network-scripts/ifcfg-em1 file from a script and it works great. However, prior to making those changes the script makes a backup copy of the original ifcfg-em1 file called ifcfg-em1_old_at_TIMESTAMP_RANDOM_NUMBER. Network manager does an “ET Phone Home” on that newly created backup file and uses that instead of the file called ifcfg-em1. How weird is that??

    Somewhere, the system is tracking that copy and identifies with it. I’ve got my hunting rifle out looking for that beastie….. No success as yet getting all this to run unattended from a script. For the record I’m loading the base system from a live media install CD reference platform 3.3.4-5.fc17.i686 and then running my script against that. During the CD install all the default options are taken with the objective of all subsequent modifications are performed by the script.

    Network manager is giving me fits.

    • http://danielgibbs.co.uk dgibbs

      I think the issue you have with the network-scripts/em1 is that you are backing up the file in to the network-scripts directory. I think that the system will read all the files in that directory including your backup file. This maybe causing some confusion for the system. Try backing up the file else where.

      I cant say I had the same issue when disabling NetworkManager. I simply turned off NetworkManager and enabled network make the modifications to the interface file and that’s it :-).

      I would expect to loose connectivity while you are making these changes so if you are not sitting in front of the server/PC or have it on a VM you might have issues.

      Hope this helps :-)

  • http://www.solrei.com Charles McGowen

    Daniel, I just discovered that the Live Install disc is imbedding network information into the LVM during install. Eeerrgh… moving to look at Fedora core and if that doesn’t work – I’ll have to spin my own distro.

    • http://danielgibbs.co.uk dgibbs

      I don’t quite understand what you mean. As LVM its only a logical volume for a partition to sit on allowing you to get one partition across multiple disks and has nothign to do with network interfaces

  • Elgger

    How do you setup this file to work with or without IPv6, and both with IPv4, cause in my case the /etc/sysconfig/network-scripts/ifcfg-eth0 contain only IPv6 informations?

  • Elgger

    Ok I’ve already found the info for configuring both IPv6 & IPv4 :
    in file : /etc/sysconfig/network
    Add or append following line:
    NETWORKING_IPV6=yes

    In file /etc/sysconfig/network-scripts/ifcfg-eth0
    #***** For IPv6 Configuration ******
    IPV6INIT=yes
    IPV6ADDR=1402:f0c0:1002:0011:0000:0000:0000:0002
    IPV6_DEFAULTGW=1402:f0c0:1002:0011:0000:0000:0000:0001
    #****** For IPv4 Configuration ******
    IPADDR=192.168.1.2
    NETMASK=255.255.255.0
    BROADCAST=192.168.1.255
    NETWORK=192.168.1.0
    GATEWAY=192.168.1.1

    • http://danielgibbs.co.uk Daniel Gibbs

      This is very useful Elgger. Thanks you providing this info :)

  • Alex

    Guys
    Make sure to add DNS as well.

  • Greg Brown

    Daniel, thank you for posting this how-to. It was just what I needed!

    Good luck with your future endeavors,

    Greg

    • http://danielgibbs.co.uk Daniel Gibbs

      Thanks Greg :)

      • http://xslasshernproductions.wordpress.com xslasshernproductions

        Would this affect my brother who is using windows?

        • http://danielgibbs.co.uk Daniel Gibbs

          Only if the IP address you set is the same as his. If you are asking this question you should probably do some reading up on networking =)

    • Ana

      I agree, quick and simple tutorial which did just what I needed. I use putty to connect to my vm and was tired of reconfiguring. I would like to second Greg’s sentiments. Thank you Daniel.

  • Pingback: GuruPlug Server Fedora Remix Penetration Testing: 0.3 Release « Kowrinanthan Dayalingam

  • Pingback: Impostare un IP statico su Fedora 17 | ZoiLab

  • oystercatcher

    I followed this tutorial on fedora 18 with some minor changes

    After disabling networkmanager

    systemctl stop NetworkManager.service
    systemctl disable NetworkManager.service

    then I copied in my case ifcfg-em1 (old p4 system)
    to a backup and made the changes you described.

    /etc/sysconfig/network-scripts/ifcfg-em1

    then I restarted NetworkManager

    systemctl enable NetworkManager.service
    systemctl start NetworkManager.service

    I think this line takes care of networkmanager
    NM_CONTROLLED=”yes”

    I tried NM_CONTROLLED=”no” along with the commands for
    the old network method but that did not work for me.

    • Aaron Gray

      For F18 stopping the network manager with :-
      systemctl stop NetworkManager.service

      followed by your original changes to ‘/etc/sysconfig/network-scripts/ifcfg-em1′, this time for 192.168.0.x network in my case :-

      IPADDR=192.168.0.128
      NETMASK=255.255.255.0
      BROADCAST=192.168.0.255
      NETWORK=192.168.0.0
      GATEWAY=192.168.0.1

      and adding

      NM_CONTROLLED=”yes”

      as suggested in previous post.

      then restarting the network manager :-

      systemctl start NetworkManager.service

      Does the trick nicely.

      Wish they would not keep changing things ….

      • Aaron Gray

        and in ‘/etc/sysconfig/network-scripts/ifcfg-em1′ :-

        DNS1=8.8.8.8
        DNS2=4.4.4.4

        BTW Your Ethernet interface may not be ‘em1′ so do a ‘ifconfig’ command and check the name of your Ethernet device.

  • Faraz Ahmad

    Can any one help me please.
    I have server with CentOs installed/
    I have two Lan Cards in it. one is given local Ip ad 192.168.1.201
    Other Lan card is given Live static IP like 203.130.16.214
    Local IP is working fine on LAN. Live ip is pinging over the internet?

    Kindly help me?? what should is need to do?

    • http://danielgibbs.co.uk Daniel Gibbs

      What do you mean by live static IP? Is this your Internet IP? It is not clear what your problem is. Please provide more information so we can try to help.

      • Faraz Ahmad

        It means i have one live ip. which i use to access my system from anywhere over the internet.

        • Faraz Ahmad

          it is working fine on a Windows server installed system. but when i installed two lan cards in linux system i am unable to access my system.
          I assigned this live ip to Lan interface eth1.

          • http://danielgibbs.co.uk Daniel Gibbs

            All I can gather so far is that you have assigned a static Internet IP to eth1 and an internal IP to eth0. Are you using the CentOS server as an internet gateway? what are you trying to use to access the server? Is the server on a home broadband connection or is it a dedicated server on the Internet? You have not really told me what the problem really is apart from its not working. Remember I do not know anything about your setup. Any infomation to tell us how you have this setup is useful

  • http://gravatar.com/wanajava masaji

    Thank you very much, it’s very helpful ;) now Linux it’s more complicated than in the first era…. :(

  • david

    route add default gw router-ip-address

  • uday

    I am using Fedora 17 via VMware player. The host OS uses a proxy server to connect to internet. what are the settings required in the virtual fedora OS so as to enable the internet connection?

    • http://danielgibbs.co.uk Daniel Gibbs

      At a guess I would make sure that the VM network adapter is set to bridged mode and then configure the proxy settings exactly the same on the VM as it is on the PC. I personalty do not know much about how to setup proxys in fedora. Hope this helps.

  • Jonathan

    Hi Daniel,

    I used your tutorial with some slight modifications with initial success in Fedora 18 on a Panda Board. The ethernet was up and I was able to browse (only opened one web page). However, after a shutdown and restart, I had no ethernet.

    My changes to your tutorial were: used eth0 instead of em1, eth0 showed up initially in ifconfig. I did not use NM_CONTROLLED and UUID. I used BOOTPROTO=none.

    When I restarted, nothing showed up for eth0 in ifconfig. So I did systemctl enable NetworkManager.Service and systemctl start NetworkManager.service. The eth0 then showed up in ifconfig. So I stopped NetworkManager.service and disabled it again. I then ran systemctl restart network.service but incurred “Job for network service failed. See ‘systemctl status network.service’ and ‘journalctl -n’ for details.

    It seems that nothing was setting up eth0 initially on boot, but now when I try to use NetworkManager to start it it again, then go through the process again, it still fails to execute.

    Any Ideas what I am missing?

    Thanks, Jonathan

  • http://www.facebook.com/satyajit.bhadange Satyajit Bhadange

    I am getting this error..what to do ?

    [root@user101 user101]# systemctl restart network.service
    Job failed. See system journal and ‘systemctl status’ for details.
    [root@user101 user101]# systemctl status
    Too few arguments.
    [root@user101 user101]# systemctl status network.service
    network.service – LSB: Bring up/down networking
    Loaded: loaded (/etc/rc.d/init.d/network)
    Active: failed (Result: exit-code) since Wed, 19 Jun 2013 12:35:57 +0530; 57s ago
    Process: 2379 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=1/FAILURE)
    CGroup: name=systemd:/system/network.service

    Jun 19 12:35:57 user101 network[2379]: [FAILED]
    Jun 19 12:35:57 user101 network[2379]: RTNETLINK answers: File exists
    Jun 19 12:35:57 user101 network[2379]: RTNETLINK answers: File exists
    Jun 19 12:35:57 user101 network[2379]: RTNETLINK answers: File exists
    Jun 19 12:35:57 user101 network[2379]: RTNETLINK answers: File exists
    Jun 19 12:35:57 user101 network[2379]: RTNETLINK answers: File exists
    Jun 19 12:35:57 user101 network[2379]: RTNETLINK answers: File exists
    Jun 19 12:35:57 user101 network[2379]: RTNETLINK answers: File exists
    Jun 19 12:35:57 user101 network[2379]: RTNETLINK answers: File exists
    Jun 19 12:35:57 user101 network[2379]: RTNETLINK answers: File exists
    [root@user101 user101]# /etc/rc.d/init.d/net
    netcf-transaction netconsole network
    [root@user101 user101]# /etc/rc.d/init.d/network start
    Starting network (via systemctl):
    Job failed. See system journal and ‘systemctl status’ for details.
    [FAILED]

  • subhashree

    I need to configure lan from my PC to raspberry pi ..OS used in raspberry pi is fedora remix. i need to install the softwares from my PC to fedora remix. can u please say the exact command

  • Pingback: Linux系列:Fedora虚拟机设置固定IP上网(配置IP、网关、DNS、防止resolv.conf被重写) – Alexia(minmin) | 查问题