Difference between revisions of "This Is Your Brain On Informatics: Network"

From Pathology Education Instructional Resource
Jump to: navigation, search
(Created page with "<p> Possibly the most important aspect to computers: the internet (or more broadly, the network). Here are some guidelines to setting up networks on Linux machines with speci...")
 
(Using a Static IP)
 
(32 intermediate revisions by the same user not shown)
Line 1: Line 1:
<p>
+
Possibly the most important aspect to computers: the internet (or more broadly, the network).  Here are some guidelines to setting up networks on Linux machines with special sections for the virtual machine controlled by [https://www.virtualbox.org/ VirtualBox].
Possibly the most important aspect to computers: the internet (or more broadly, the network).  Here are some guidelines to setting up networks on Linux machines with special sections for the virtual machine controlled by <a href="https://www.virtualbox.org/">VirtualBox</a>.
+
 
</p>
+
== Getting Started ==
 +
This first item of note is the location of the file that names the network connections in Linux.  This file can be found [[This Is Your Brain On Informatics: Common Pathnames|here]] under the network section.  Upon being opened the file should show something similar to this (# indicates a comment):
 +
 
 +
<pre>
 +
# The loopback network interface
 +
auto lo
 +
iface lo inet loopback
 +
 
 +
# The primary network interface
 +
auto eth0
 +
iface eth0 inet dhcp
 +
</pre>
 +
 
 +
The networks shown here are the basic networks that will allow the machine to connect to the internet.  If this is a regular computer (not a virtual machine), this file should be similar to what is above meaning that it is already completely setup for internet connection and ssh purposes.
 +
 
 +
Notice here that the eth0 network has "dhcp" (dynamic host configuration protocol) at the end of the final line.  This causes the IP address of this network to be dynamically acquired (meaning that the IP address will be changed frequently) rather than statically set.  Below is a discussion of how to set up each.
 +
 
 +
== Adding a network ==
 +
This step should be taken care of if it is a regular computer; however it is very necessary for a virtual machine.
 +
 
 +
=== Using a Dynamically Acquired IP ===
 +
This method will cause the network to randomly (within reason of course) select an IP address each time the virtual box is disconnected from an ISP (Internet Service Provider) or another virtual machine is created.
 +
 
 +
'''Vitual Machine Note'''<br />
 +
This step is critical to allowing the virtual machine to interact with the outside world and not have a host only network. The steps below are for a virtual box, but can be applied to any other network setup in Linux.
 +
 
 +
# Access the above pathname with pico (pico /etc/network/interfaces)
 +
# Below the first network (indicated by eth0), copy the first network, replacing eth0 with eth1
 +
#::::auto eth1
 +
#::::iface eth1 inet dhcp
 +
# Reboot the machine
 +
# Determine the new IP address of the eth1 network by one of the following
 +
## After logging in, check the IP next to the eth1 network
 +
## Type "ifconfig" into the command line and check the IP next to the "inet addr:"
 +
 
 +
=== Using a Static IP ===
 +
This can be used if it is necessary to prevent the IP address from changing (e.g. a home server or you're just sick of having to adjust the IP for every program that connects to the virtual machine each time it changes).  Below is an example of how it is set.
 +
 
 +
<pre>
 +
# This is the network that allows communication with the outside world
 +
auto eth1
 +
iface eth1 inet static
 +
        address  192.168.56.23
 +
        netmask  255.255.255.0
 +
        network  192.168.56.0
 +
        broadcast 192.168.56.255
 +
        gateway  192.168.56.1
 +
 
 +
</pre>
 +
 
 +
 
 +
The key component of this is the word ''static'' at the end of the line beginning with ''iface'', forcing the IP address to bet set statically as determined by the user.  Each of the components of the network must now be set individually.  The address is the network address and can be set to anything.  Typically only the last number is changed from what is currently set. The current IP address can be determined by using the Linux command [[This Is Your Brain On Informatics: Linux Commands|''ifconfig'']] and looking at the ''inet addr'' under the appropriate network.  ''Bcast'' will determine the ''broadcast'' and ''netmask'' will determine the Mask.  As long as only the final number of the IP address is changed, then these can be used as shown above. 
 +
 
 +
The final numbers (''network'' and ''broadcast'') can be set by simply using 0 and 255 respectively for the last number.  Finally, the ''gateway'' is the IP address of the router used to access the internet.  This can be accessed from the router settings.  The ''gateway'' should NOT be set for a '''Virtual Machine''' through VirtualBox.  It should only be set for an actual computer.  The gateway is typically the same first three numbers as the IP address with a ''1'' as the last number.
 +
 
 +
 
 +
{{This Is Your Brain On Informatics}}
 +
 
 +
[[Category:This Is Your Brain On Informatics]]

Latest revision as of 06:58, 17 November 2014

Possibly the most important aspect to computers: the internet (or more broadly, the network). Here are some guidelines to setting up networks on Linux machines with special sections for the virtual machine controlled by VirtualBox.

Getting Started

This first item of note is the location of the file that names the network connections in Linux. This file can be found here under the network section. Upon being opened the file should show something similar to this (# indicates a comment):

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

The networks shown here are the basic networks that will allow the machine to connect to the internet. If this is a regular computer (not a virtual machine), this file should be similar to what is above meaning that it is already completely setup for internet connection and ssh purposes.

Notice here that the eth0 network has "dhcp" (dynamic host configuration protocol) at the end of the final line. This causes the IP address of this network to be dynamically acquired (meaning that the IP address will be changed frequently) rather than statically set. Below is a discussion of how to set up each.

Adding a network

This step should be taken care of if it is a regular computer; however it is very necessary for a virtual machine.

Using a Dynamically Acquired IP

This method will cause the network to randomly (within reason of course) select an IP address each time the virtual box is disconnected from an ISP (Internet Service Provider) or another virtual machine is created.

Vitual Machine Note
This step is critical to allowing the virtual machine to interact with the outside world and not have a host only network. The steps below are for a virtual box, but can be applied to any other network setup in Linux.

  1. Access the above pathname with pico (pico /etc/network/interfaces)
  2. Below the first network (indicated by eth0), copy the first network, replacing eth0 with eth1
    auto eth1
    iface eth1 inet dhcp
  3. Reboot the machine
  4. Determine the new IP address of the eth1 network by one of the following
    1. After logging in, check the IP next to the eth1 network
    2. Type "ifconfig" into the command line and check the IP next to the "inet addr:"

Using a Static IP

This can be used if it is necessary to prevent the IP address from changing (e.g. a home server or you're just sick of having to adjust the IP for every program that connects to the virtual machine each time it changes). Below is an example of how it is set.

# This is the network that allows communication with the outside world
auto eth1
iface eth1 inet static
        address   192.168.56.23
        netmask   255.255.255.0
        network   192.168.56.0
        broadcast 192.168.56.255
        gateway   192.168.56.1


The key component of this is the word static at the end of the line beginning with iface, forcing the IP address to bet set statically as determined by the user. Each of the components of the network must now be set individually. The address is the network address and can be set to anything. Typically only the last number is changed from what is currently set. The current IP address can be determined by using the Linux command ifconfig and looking at the inet addr under the appropriate network. Bcast will determine the broadcast and netmask will determine the Mask. As long as only the final number of the IP address is changed, then these can be used as shown above.

The final numbers (network and broadcast) can be set by simply using 0 and 255 respectively for the last number. Finally, the gateway is the IP address of the router used to access the internet. This can be accessed from the router settings. The gateway should NOT be set for a Virtual Machine through VirtualBox. It should only be set for an actual computer. The gateway is typically the same first three numbers as the IP address with a 1 as the last number.