注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

骐骥一跃

日积跬步 业精于勤荒于嬉

 
 
 

日志

 
 

[原创]FreeBSD学习笔记05-配置静态IP  

2008-06-12 15:06:39|  分类: Unix/Linux |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

( 声明:原创文章,未经授权,不得转载。作者:印第安 http://blog.kysf.net

  

1.8. CONFIGURING A STATIC IP

It is important for a server to have a static IP or permanent address for much the same reason a person needs a phone number: It allows callers or clients to reach the recipient. FreeBSD uses a file named rc.conf to establish the system's IP address, among other settings, during system startup. In this section we'll customize the rc.conf file to reflect your server's intended configuration.

The rc.conf file contains configuration settings for the computer's hostname, network interface cards, and which services to start at boot time. It is important that the settings in this file are correct; a typo here could hamper the system's functionality.


Note: The following discussion assumes that you're building your FreeBSD system to function as an Internet server. If this is not the case, then the options we selected during installation should be sufficient and you can skip this section.

We will cover two scenarios for configuring a static IP address:

  • Server behind a NAT (Network Address Translation) router

  • Server directly connected to the Internet

1.8.1. A. FreeBSD Server Behind a NAT Router

A small office or home network commonly has one Internet connection that needs to be shared by multiple computers. A NAT router allows the sharing of a single Internet connection within the local (private) network. The router functions as a firewall, creating a protected zone in the private network by allowing all traffic out, but only allowing known or solicited traffic in.

Port Forwarding

Most NAT routers provide a port-forward function that forwards traffic received at the router to a computer with a static IP address inside the private network. If, for example, you were hosting a web server, you would need to forward TCP port 80 (the IANA standard for HTTP) to the IP address of your FreeBSD server. (See your router's documentation for details on port forwarding.)

Most NAT routers that support port forwarding have built-in DHCP servers that assign computers in the private network a dynamic IP address, one that may change each time the computer logs on to the network.

DHCP works when machines simply need to connect to a network and get the first available IP address, but it's no help to you if you want to use your FreeBSD system as a server. You'll need a static (permanent) IP address so that information destined for your server will arrive.

Modifying rc.conf to Specify a Static IP Address

To specify your server's static IP address you'll modify rc.conf. But first you need to tell the DHCP server to assign IP addresses in a range that doesn't conflict with the server's IP address.

Your router's DHCP options should allow you to set the starting IP address (consult your router's documentation for details). For this example, we'll use 192.168.1.12 as the starting address for the range of addresses that can be assigned to machines, knowing that numbers are assigned from this address up (.13, .14, .15, and so on). We'll assign 192.168.1.11 as your server's static IP address since it is outside the range of the DHCP server.

Now let's set this in rc.conf. Open rc.conf:

# ee /etc/rc.conf

You should see something like the following in your rc.conf file (~7). Your FQDN should be here if specified during setup; the xl0 may be different.

hostname="host.example.com"  ifconfig_xl0="DHCP"


Note: If you don't already have the hostname set, be sure to set it correctly. The hostname should be your system's fully qualified domain name; host is the name of the machine and example.com is your registered domain name.

Insert your router's IP address in the defaultrouter statement as shown below (~7). Using our example scenario above, the hostname, ifconfig, and defaultrouter statements should now look like this:

hostname="host.example.com"  ifconfig_xl0="inet 192.168.1.11 netmask 255.255.255.0"  defaultrouter="192.168.1.1"

Notice that we have replaced "DHCP" with our static IP address and added the netmask address (255.255.255.0 is the default netmask address in most configurations).

We've also added a defaultrouter line which points to the NAT router's IP address. This address, 192.168.1.1, will be the IP address you enter into your web browser to access the router web configuration; this is also called the default gateway.

Now save and exit. (Skip to "Dynamic DNS".)

1.8.2. B. FreeBSD Server Connected Directly to the Internet

If your FreeBSD system is connected directly to a cable or DSL modem and you have correctly entered your FQDN during configuration step 4 above, no further configuration is necessary. However, if you did not enter a hostname during the DHCP configuration, then you will need to edit /etc/rc.conf to include your FQDN.

Open rc.conf with Easy Editor:

# ee /etc/rc.conf

rc.conf (~7) should look like this (replace host.example.com with your FQDN):

hostname="host.example.com"

1.8.3. Dynamic DNS

Dynamic DNS is a service provided by third-party companies that keeps track of a computer's public IP address. These providers automatically update your domain name's associated IP address if it changes for any reason. Most Internet service providers use DHCP servers to assign public IP addresses to their customers dynamically. Unless you pay for a static IP address, this dynamically assigned address may change from time to time.

When you register your domain name, you can specify the target IP address of your server if you wish to host your own services. Many people mistakenly assume that their current, dynamic IP address will be theirs indefinitely. When your dynamic IP address changes (which may happen frequently or once every few months), you appear to "drop off " the Internet since your domain registrar's records point to the previous IP address, which is no longer valid. You would then have to go back to your domain registrar and notify them of your new IP address to regain your Internet presence (this is usually accomplished through a web-based control panel).

This is where dynamic DNS service providers become useful. These third-party companies allow you to keep your IP address updated by using a client program on your server to detect when the IP changes. When it does, the client program automatically contacts the dynamic DNS service to update your DNS record so you stay "live." When using these services you need to point your domain registrar to your dynamic DNS service's servers, which then point to your updated IP address. Most dynamic DNS providers charge a fee for their services, though there are a few free ones, like ZoneEdit (http://zoneedit.com). By combining a dynamic DNS service provider with a dynamic DNS updating client like ddclient, you can provide a static IP-like Internet presence. See "ddclient 3.7.3" for information on ddclient.

 

 

( 声明:原创文章,未经授权,不得转载。作者:印第安 http://blog.kysf.net ) 

  评论这张
 
阅读(2571)| 评论(0)
推荐

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018