• Aucun résultat trouvé

Configuring Your Address

Dans le document Setting Up LAMP: (Page 135-138)

would allow for 16 subnets. This is because 240 in binary is 4 bits (11110000), and 2 to the power of 4 is 16. Now to determine how many hosts you are allowed to have for each subnet, you must look at how many bits off you have in 240 (11110000). In this case it is 16 as well.

However, you must lose two because the first must be your subnet address and the last must be the broadcast address. This gives you 14 hosts per subnet.

In addition, specific IP addresses are reserved for special purposes. Two examples are 0.0.0.0 and 127.0.0.0. The first specifies the default route used for IP, and the second is the loopback address. If datagrams are sent to the loopback address, the machine will treat the packet as if it came from a different network. This enables you to develop and test applications and programs that use networking without having to set up an entire network or more than one computer to send and receive from. All development can be performed isolated on a single machine.

After you choose which class is right for your application, you must then decide whether to assign each host a static IP address individually or to use the Dynamic Host Configuration Protocol (DHCP). We touched on this briefly during Chapter 2. Running one of your machines, usually the gateway, as a DHCP server will enable any machine that attaches to your local network to be automatically assigned an IP address. The next section will help you decide which method is best suited to your purpose and will detail how to set up each type of environment.

Configuring Your Address

Now that you know the basics of IP addressing, you can begin to look objectively at which solution is best suited for your situation. Static IPs will give you definite IP addresses for each machine on your network and will never change if the machine becomes disconnected or needs to reboot. Even if you are running a DHCP server, however, you can still use static IP addresses that fit in the range of your network configuration. For our examples within this chapter, we will be using Class C IP addresses because it is unlikely you will need to create subnets for your first Linux server.

First decide whether this machine is going to be connecting to a gateway or connecting directly to the Internet. If it will be connecting directly to the Internet, you need to specify only your Internet IP address as a static IP. If you are connecting through a gateway, you need to specify your internal address either by entering a static IP or by configuring your server to connect to your network’s DHCP server. After this is completed, you need to tell your fire-wall, if you are using one, to allow traffic for the ports you want available to your server’s IP address. This will allow outside users who are directed to your server’s IP address access to the specified ports.

4337Book.fm Page 113 Saturday, June 19, 2004 5:24 PM

114

Chapter 5 • Network Connectivity

There is one other solution you might be implementing, and that is configuring your server on a network, although it does not need to serve pages to the outside world. This would be the case if you are using this server as a development platform and only people involved in the project need to access this machine from your local network. This setup gives you the oppor-tunity to either give your machine a static IP address or use the DHCP server on your network to automatically obtain one.

In this section, you’ll learn how to change the proper settings on your server to fit your needs.

Static IP

IP addresses must be assigned to an individual Ethernet device. The configuration file for each device is located, on Fedora Core 2, under the following directory:

/etc/sysconfig/network-scripts/

Each file will be named ifcfg-ethX, where X is the number of the device. If multiple addresses need to be assigned to a single device, you can also configure virtual devices. They use the same filename with a colon and virtual device number following the device file. The following shows eth0 configured with its main configuration file and three virtual devices:

-rw-r--r-- 1 root root 108 Feb 26 11:51 ifcfg-eth0 -rw-r--r-- 1 root root 108 Feb 26 11:51 ifcfg-eth0:1 -rw-r--r-- 1 root root 108 Feb 26 11:51 ifcfg-eth0:2 -rw-r--r-- 1 root root 108 Feb 26 11:51 ifcfg-eth0:3

If you need to create another device or virtual device, you can simply copy one of the existing files and edit it to change its configuration. Go ahead and pico your ifcfg-eth0 file and take a look at its contents. You should get something similar to the following:

DEVICE=eth0 ONBOOT=yes BOOTPROTO=static IPADDR=192.168.0.13 NETMASK=255.255.255.0 GATEWAY=192.168.0.1

This configuration says that the network device eth0 will be active ONBOOT and uses a static IP address that is given on the IPADDR line. It also shows the netmask and gateway for this device as well, because our test box needs to use a gateway. You should note that in a virtual device, your device line needs to read just as your filename does, with a colon and the virtual device number.

After you have edited the required information, you can save and exit. Repeat this process for each device and virtual device and you will be ready to bring the network interfaces down and then back up again. To do this, you need to use the commands ifup and ifdown. The only argument you need to pass in is the device. You do not need to bring each virtual device up

115

Configuring Your Address

separately. Bringing up the device itself will automatically bring the others up. Go ahead and run the following:

ifdown eth0

If the command is successful, you will not receive any message. Now run its counterpart, using this command:

ifup eth0

If you do not receive any error messages, everything has been successful.

You can try to test your connection by using ping domainName to ping a known server You should be returned lines of information telling you how long each ping took. If you are not returned this information, you need to do some basic troubleshooting.

First, see if the ping is even initiating. You might receive an error message that states the domain is an unknown host. If this is the case, and you know that your domain name is correct, you should try pinging your gateway. If you are unable to ping your gateway, you know you need to troubleshoot your networking device. If you are able to ping your gateway, you know that your internal network is configured properly and you need to troubleshoot your DNS config-uration. You can further check this by specifying an IP address instead of a domain name. Use a known good IP address that accepts pings and try again. If it works, then you just need to reconfigure your DNS. See the section “Using DNS” later in this chapter for more information.

If your domain name is resolving and your pings are timing out, you have a problem with your network configuration. This means that your machine can access your DNS but not the rest of the world. You then need to double-check your configuration files that you just edited for any errors. After you have located your problem, remember to bring your interfaces down and then back up again in order for the changes to take effect. Then use the ping command to test your connection again.

DHCP

To configure DHCP on your machine, we will assume you are using a separate machine for your DHCP server. Just like the static IP address configuration, you will be editing the ifcfg-ethX files located in the /etc/sysconfig/network-scripts/ directory. There are only a few differ-ences in the file configuration between static and dynamic assignments: the IPADDR line, which will not exist, and the BOOTPROTO, which should read dhcp. Here is an example:

DEVICE=eth0 ONBOOT=yes BOOTPROTO=dhcp NETMASK=255.255.255.0 GATEWAY=192.168.0.1

4337Book.fm Page 115 Saturday, June 19, 2004 5:24 PM

You can also choose to leave the NETMASK and GATEWAY lines off, and Linux will attempt to retrieve the proper netmask and gateway for your system from the DHCP server. In this case, because your DHCP server will be assigning your machine an IP address in the range of 192.168.0.50–150, it will also assign Class C network values and will use 255.255.255.0 for your netmask. Your gateway will most likely be 192.168.0.1, unless it has been set up differ-ently on your DHCP server.

TIP For both static and dynamic IP addresses, you can also use the netconfig command. This will launch an ANSI graphic program that will enable you to configure your network inter-faces. Anything changed this way will be written to the proper configuration files and will be activated immediately.

Remember that if you are using this server as a web server for the outside world, your machine must have a static IP address associated with its domain name. If this is the case and you are using DHCP, you need to configure your router to associate the outside static IP address with your internal static or dynamic IP address. If you are directly connected to the Internet and use the static IP address, which your domain name(s) resolve to, you do not need to perform any addi-tional setup. If you are setting up an advanced network or will be connecting to the Internet via an advanced network, you need to contact your network in order to coordinate your configu-ration; we recommend that you purchase a book devoted to this topic if you will be designing and implementing the network yourself.

Dans le document Setting Up LAMP: (Page 135-138)