Configuring Network in CentOS 6.3 Virtual Box + Screenshots

Posted: May 23, 2013 in Uncategorized
Tags: , , , , , , , , ,

This is a guide on configuring network in CentOS 6.x in Virtual Box with screenshots (using terminal).

[UPDATE: This guide can also be used to configure network on CentOS 6.5]

So, here I have used CentOS 6.3 minimal and will be discussing on configuring the Virtual Box and CentOS for network access. If you need help installing CentOS minimal in the Virtual Box, you can find the instructions in my earlier post here.

Requirements:

  1. Virtual Box
  2. CentOS 6.3 or 6.5 (I have tested this on CentOS 6.3 and CentOS 6.5, you can use it on other 6.x versions too)

Step 1: Configure Virtual Box Network Settings:

There are different modes or ways you can configure your Virtual box network settings.

  1. Not Attached
  2. NAT
  3. Bridged Adapter
  4. Internal Network
  5. Host-Only Adapter
  6. Generic Driver

You can find more details about the different modes here.

I will be using the Bridged Adapter mode for this guide. It is faster as it treat the VM as an individual host within the network.

Open Virtual Box and right click on  your CentOS VM, and click on “Settings“.

vbox settings

Now, go to the tab Network and change the “Attached to” field to “Bridged Adapter”. Then choose the “Name” to your network interface. For example, I have a dell wireless adapter, so I choose the Name as “Dell Wireless” from the drop down menu. And finally check the field “Cable Connected.  Finally, click on OK when you are done.

network settings

So, you have now configured the Virtual Box. Now, you can start your CentOS VM by selecting you VM and clicking on “Start”.

start vm

Step 2: Configure CentOS network settings:

You can configure your network either by using Dynamic IP addressing assigned by your DHCP server or you can manually configure your IP Address statically. You can choose either static or dynamic method and can do so by editing the file /etc/sysconfig/network-scripts/ifcfg-eth0.

Method 1: Dynamic IP 

We can configure the network by using Dynamic IP address which are assigned automatically by the DHCP server. This is the simplest way to configure your network.

NOTE: You will have a line that starts with HWADDR in the your config file, do not change or modify that line.

In your terminal, type the following:

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

Now, add/modify the file as follows (DO NOT CHANGE the HWADDR line your config file):

DEVICE=eth0

BOOTPROTO=dhcp

ONBOOT=yes

NM_CONTROLLED=no

HWADDR=08:00:27:08:47:E9

Now, save the file by pressing “ESC” and typing :wq and hit ENTER.

To view your network config file. type the following in the terminal:

cat /etc/sysconfig/network-scripts/ifcfg-eth0

dynamic ip config

Now, you will have to restart your network. You can do so by typing the following in the terminal:

                service network restart

service network restart

To view your IP address, type the following in your terminal:

                ifconfig eth0

You can see your IP Address of the interface eth0 next to the field “inet addr:” as shown below:

ifconfig eth0

Now, if you have internet access, then you can check if you are able to ping any website. And you should be able to get the reply. For example, in your terminal type:

ping extr3metech.wordpress.com

ping results

You can press CTRL+ C to stop the ping command.

So, Hurray! you have successfully setup up your network in your CentOS Virtual Box.

Method 2: Static IP

We can also assign the network information manually by assigning the IP Address, NETMASK , GATEWAY in the network interface config file.

NOTE: You will have a line that starts with HWADDR in your config file, do not change or modify that line.

Step1 : In you terminal, type:

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

Now, edit/merge the file to the following

DEVICE=eth0

BOOTPROTO=static

ONBOOT=yes

NM_CONTROLLED=no

HWADDR=08:00:27:08:47:E9

IPADDR=192.168.1.30

NETMASK=255.255.255.0

GATEWAY=192.168.1.1

Now, press ESC and type :wq and hit ENTER to save and exit the configuration file.

To view the config file. type the following in the terminal:

cat /etc/sysconfig/network-scripts/ifcfg-eth0

view configuration

Step 2: Change Host name: 

To change host name , you have to edit the config file /etc/sysconfig/network. If you want to know to change the host name manually, you can follow the guide I have posted earlier here.

Step 3: Assign DNS Server IP

To manually assign primary and secondary DNS Server IP addresses, in your terminal type: 

vi /etc/resolv.conf

Now, edit this file to the following:

nameserver 8.8.8.8          

nameserver 8.8.4.4

Now, press ESC and type :wq and hit ENTER to save and exit the configuration file.

Now, if you want you can make sure you have entered and saved the correct configuration(It is a good practice to double check 😀 ). To view your dns config file, in your terminal type:

cat  /etc/resolv.conf

/etc/resolv.conf

Step 4: Restart network:

Finally, all you have to do is to restart your network service. To so so, type the following in the terminal:

                service network restart

service network restart

Now, you can check your Current IP configuration, by typing the following in the terminal:

ifconfig eth0

ifconfig eth0

Now, if you have internet access, then you can check if you are able to ping any website. And you should be able to get the reply. For example, In your terminal type:

ping extr3metech.wordpress.com

 ping results

You can press CTRL+ C to stop the ping command.

So, Hurray! you have successfully setup up your network manually in your CentOS Virtual Box.

Hope this guide helped you to configure network in your CentOS Virtual Machine.

If you have any queries or suggestions regarding this guide, feel free to leave a comment and will get back at you. Don’t forget to follow my blog to get future updates! :D

ΞXΤЯ3МΞ

 
Comments
  1. Deepak says:

    These steps are perfect!!! Thank you so much EXTR3ME

  2. Gaetan de Speville says:

    Thank you for a very straight forward explanation that works.

  3. Anand says:

    Nice tutorial buddy
    I have installed this on a dedicated server, is there any way I can connect to the system via ssh from a remote machine.
    In fact, I have been trying to figure this out since 3 hours but have failed to achieve.

    • ΞXΤЯ3МΞ says:

      @Anand, you need to install openssh server in your dedicated server and make sure port 22 is open and the service is started. For your information, the config file will be located in /etc/ssh/sshd_config

      In the client, install the ssh client and you should be able to connect to the server.

      Let me know if you need any further help. You also can subscribe to get future updates.

      Regards
      ΞXΤЯ3МΞ

  4. moscardo says:

    Hi, i’d like to thanks for your great effort to help and explain step by step with excellent text with pictures.

  5. Pedro says:

    This was exactly what I needed!

  6. Leandro says:

    Nice.

  7. Pavel says:

    Thanks a lot.

  8. Nofear says:

    Thank you very much for this outstanding work.

  9. Marcio says:

    Thanks, very helpful!

  10. Albert says:

    hi. I have 2 boxes with fedora ( for development) and CentOS 6.4. I am going to use wireless. if you are using wireless instead of eth0, would the process be the same?.
    Thank you

    • ΞXΤЯ3МΞ says:

      @Albert , It should work. As you can see , I have used my Dell wireless connection in my virutal box setup as shown in the image https://extr3metech.files.wordpress.com/2013/04/nw-settings.jpg .I simply edited the default interface name eth0 for simplicity. If you want , you can also create another interface like wlan0 and edit it instead of editing eth0. Let me know about your experience with setting it up and post here if you need any further help. Hope this helps!

      Regards
      ΞXΤЯ3МΞ

  11. Doãn Son says:

    Thanks you very much !

  12. Fachim says:

    Hey man, it is amazing, we use it for web development server, and you save us a lot. thanks 🙂

  13. Patrick says:

    when i try service network restart it says: Device eth0 does not seem to be present, delaying intialization [FAILED]

  14. Calcifer says:

    Gracias amigo estupendo tutorial me servio mucho.saludos

  15. Zerox says:

    what i have to type in my local machine to enter in the web config?

  16. Dinesh says:

    Thank you Its really Useful.

  17. Nice one, saved me hours of head scratching as a CentOS newbie.

  18. Thanks..It is a great post

  19. Eric says:

    If I choose dhcp, my network address becomes a private address, like 192.168.2.3. I get internet connection, so it works fine. Is there a possibility to give centos the same ip as the external (static) ip address of the internet connection?

    (I have a Airport Extreme router between them inside my network.)

    I have tried the static option you described and set the ip address as the external address (62.x.x.x) and filled in the subnet mask and router address and dns. But when I try this the internet connection gets lost.

  20. Frosty says:

    Extremely Helpful

  21. Hermione says:

    Brilliant! you saved my life

  22. Irvan Wahyu says:

    nice tutorial this work perfectly
    can you add some tutorial about how to add repository in centOS.. it will be so helpfull..
    thanks

  23. Adam Cooper says:

    Just what I needed. Thanks!

  24. Paul says:

    The MAC address in your screen shot is different than the HWADDR in your config file. Is that a mistake? Most resources on the net say those need to be in sync.

    • ΞXΤЯ3МΞ says:

      @Paul, When you initially edit the file, there would be a HWADDR already in the config file which would be already in sync with the MAC address mentioned under network settings of the Virtual Box. I have mentioned in the section “Method 1: Dynamic IP”, to keep the default MAC address in your config file as it is, as it would be already in sync. (In the screenshot, the MAC is different, I had changed the MAC address for testing purposes). And yes Paul, these settings must be in sync. Hope I have clarified all your quires. Leave a comment if you have any further queries. Hope this helps!

      Regards
      ΞXΤЯ3МΞ

  25. Karadeniz says:

    Nice tutorial. I was failed to install Centos 64-bit using all DVD/CD iso’s other than the minimal install I did not why, Therefore this tut is very usefull

  26. zmozmo says:

    I would like to see GUI for CentOS. could you kindly explain me please how to do that?

  27. Thank Extreme… Good luck for you 🙂

  28. Periklis says:

    just wanted to say thanks for the detailed guide, it helped me!

  29. Thanks for posting this, it helped tremendously!

  30. luismalamoc says:

    thank you very much…

  31. Nepiddd says:

    Awesome post and very helpful. Thank you.

  32. Quan says:

    Thanks very much! 🙂

  33. SPR says:

    Hi ..i have configured Oracle virtual box and ontop of it ihave installed oracle linux6.4 ..i want to connect inter through my virtual machine but i can’t.Eeven i have configured everything what you have mentioned but i can’t please assist me on this. Here i have configured DNS and hostaname and all..please find the below

    Its all configured Bridged adaptor in virtual box.

    ————————–
    [root@oraclelinux6 ~]# cat /etc/hosts
    3.209.xxx.x oraclelinux6.localdomain
    ————————————–
    [root@oraclelinux6 ~]# route
    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    default 3.209.xxx.x 0.0.0.0 UG 0 0 0 eth1
    3.0.0.0 * 255.0.0.0 U 1 0 0 eth1
    192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
    ——————————————————————————–
    [root@oraclelinux6 ~]# cat /etc/resolv.conf
    # Generated by NetworkManager
    search localdomain
    nameserver 3.209.xxx.xx
    nameserver 3.209.xxx.xx
    [root@oraclelinux6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
    DEVICE=”eth1″
    BOOTPROTO=static
    IPADDR=3.209.xxx.x
    NETMASK=255.255.255.0
    GATEWAY=3.209.xxx.x
    DEFROUTE=yes
    ONBOOT=yes
    TYPE=Ethernet
    PREFIX=8
    DNS1=3.209.xxx.xx
    DNS2=3.209.xxx.xx
    IPV4_FAILURE_FATAL=yes
    IPV6INIT=no
    NAME=”System eth1″
    UUID=9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04
    LAST_CONNECT=1397468379
    ———————————————————————————-
    [root@oraclelinux6 ~]# cat /etc/sysconfig/network
    NETWORKING=yes
    HOSTNAME=oraclelinux6.localdomain
    GATEWAY=3.209.xxx.x
    ——————————————————————————–
    [root@oraclelinux6 ~]# ping google.co.in
    ping: unknown host google.co.in
    [root@oraclelinux6 ~]# ping yahoo.com
    ping: unknown host yahoo.com

    Can you please help me where i did wrong??

  34. SPR says:

    ..typo error on the above

    “I want to Connect internet*” through my Virtual machine(OEL 6.4)

  35. John says:

    Excelent!!, thank you!! very util!!

  36. Pablo says:

    Thanks a lot! I read a bunch of posts on other websites, everyone of them over complicated this stuff and I still wasn’t able to provide connectivity to the box. Your steps worked to perfection for me.

  37. A lot of thanksgiving around, but couldn’t help but not adding to these! Very helpful step-by-step indeed!

  38. needingsleep3 says:

    This made my life easier, thanks.

  39. Zero says:

    Thanks A Lot

  40. satria says:

    thanks a lot. its working 🙂

  41. A really good tutorial! 🙂 How would I be able to connect to that CentOS-Server with a virtual (let’s say Fedora) Client within Virtualbox? Will I have to do this via the bridged connection?

    • ΞXΤЯ3МΞ says:

      @Kenneth Plasa, Thanks! Yes, you can connect your Centos VM with another linux vm using bridged connection if you have setup CentOS in bridged mode as mentioned in the above tutorial. There are also other methods you can use to connect/network your VMs together and you can read more about them by using this link: https://www.virtualbox.org/manual/ch06.html

      Hope this helps.

      Regards
      ΞXΤЯ3МΞ

  42. jc says:

    Thank you for taking the time to post this. The steps were perfect and worked well for me.

  43. babkamen says:

    Thanks very very much, man. I spent almost 4 hours before have found this tutorial!

  44. ade says:

    Thank you so much. Very usefull

  45. Meg says:

    Dynamic IP worked perfectly for me for CentOS 6.6 🙂 thanks!

  46. dude says:

    Thanks, working here too on centos 6.7

  47. Sean says:

    I’m getting “unknown host http://www.google.com” when I try to ping. I went through this tutorial in full. Any suggestions on what the problem could be? I’m running VirtualBox on a system of machines that is connected to our companies internal network, but also has a network switch for the system of machines to be able to talk to one another directly.

    Any type of help/feedback is appreciated!

    • ΞXΤЯ3МΞ says:

      Hi Sean,

      Are you behind a company firewall? Did you restart your network after configuration? Also, did you change your virtual box network setting to “Bridged Adapter”?

      It would be great if you could post output of the following :

      # cat /etc/redhat-release

      # ifconfig

      # cat /etc/resolv.conf

      # cat /etc/sysconfig/network-scripts/ifcfg-eth0

      # ping 192.168.1.1

      Regards,
      ΞXΤЯ3МΞ

  48. works great brother thnku……

  49. Viraj says:

    Excellent guide thanks a ton!!!

  50. Albert Tusky says:

    Thanks a lot i am now able to work. my vm can connect to internet

  51. Dipankar says:

    I am using ClouderaVM for centos6.7. Recently, i tried to update centos 6.7 using ‘yum update’ command and stopped it without completing the update. Now I am able to ping ‘www.google.com’ but while using firefox, I am not able to connect to internet and getting error ‘Server not found’. Also yum is also not working now and giving error [Errno 14] PYCURL ERROR 6 : ”Could not resolve host ‘mum-bluecoat01” . Could you please help me here?

  52. Ben says:

    Hello Anoop. Thanks for your step by step guide.

    I was able to configure static ip for centos 7 running on a virtualbox using your steps.

    However, the static ip often change to dynamic ip during a long-running scp job to another centos. Static ip would then return with network restart.

    Any idea on how to avoid this ip change?

  53. Shashikant Mahajan says:

    Good Article! Really helpful..

  54. Sagar Shinde says:

    Hi, when i try to assign static ip to centos 6.6.in VM virtual Box.static ip successfully configured but need to connect internet connection not able to connect
    kindly help on this

  55. Konstantin says:

    Big thanks! Have no idea what exactly fixed my problem, but it is fixed now

  56. subhash says:

    Thank you very much. This was exactly what I needed also I really appreciate to your blogs.

Leave a comment