Thursday, February 28, 2013

Wireless Sensor Network

Overview

The NI Wireless Sensor Network (WSN) system is built on an IEEE 802.15.4 wireless mesh network. The 802.15.4 radio in each NI WSN device provides for low-power communication of measurement data across a large network of devices. NI-WSN software builds on top of that to provide network configuration and reliable communication from the host PC or Programmable Automation Controller (PAC) to the NI WSN-32xx node devices.

Wireless Sensor Network Components

A wireless sensor network (WSN) is a wireless network consisting of spatially distributed autonomous devices that use sensors to monitor physical or environmental conditions. These autonomous devices, known as routers and end nodes, combine with a gateway to create a typical WSN system. The distributed measurement nodes communicate wirelessly to a central gateway, which acts as the network coordinator in charge of node authentication, message buffering, and bridging from the IEEE 802.15.4 wireless network to the wired Ethernet network. where you can collect, process, analyze, and present your measurement data. Figure 1 shows a typical NI Wireless Sensor Network, in which the three WSN measurement nodes are configured as end nodes.


Figure 1.  Basic WSN System with End Nodes, Ethernet Gateway, and Host PC

 

End Nodes vs. Routers

NI WSN measurement nodes can be configured to act as end nodes or routers using the NI Measurement & Automation Explorer (MAX) utility.  In both configurations, the nodes can collect measurement data from sensors, control their DIO channels, or be programmed using LabVIEW WSN for more advanced capabilities.  One trade-off to consider when configuring nodes is power consumption. To preserve battery power, an end node will reside in a low-power sleep mode most of the time (depending on its user-defined sample interval), waking up only to sample and transmit data, along with other housekeeping information.  A router node, however, is always awake and can relay data from other nodes back to the gateway.  This allows you to extend distance and reliability in your wireless sensor network.  Because they are always transmitting data, router nodes are designed to use external power at all times to send, receive, and buffer messages to and from end nodes.

Mesh Networking

The gateways and nodes work together to form a mesh network. The gateway maintains a list of nodes (by serial number) that have been authorized for network access. When a node powers up, it scans for available networks, locates either a gateway or router, and attempts to join it. If the gateway has the node in its list, the node joins the network, downloads the latest configuration from the gateway, and begins its normal operation of acquiring measurement data and controlling DIO.
Since each node joins a network instead of a particular router or gateway, it can find a new path back to the gateway in the event that the signal is lost or blocked to its existing network route. In this way, the mesh network is inherently self-forming and self-healing. However, this may also cause network throughput to decrease, as there is no way to force a router or end node to join to a particular device in the network. Each time a node joins through a router, the overall throughput of that node is halved, due to the fact that the node must hop to get its messages back to the gateway. Figure 2 shows an example of one possible mesh configuration.



Figure 2.  Mesh Configuration #1 with Router Nodes and Gateway

In this configuration, R1 (a router) and R2 (a router) both communicate directly with the gateway. Measurements taken by both devices can directly reach the gateway without having to hop through another node. However, the configuration above does not always mesh in the same way. Figure 3 shows another possible configuration for the same network.



 Figure 3.  Mesh Configuration #2 with Router Nodes and Gateway

In this configuration, R1 can still communicate with the gateway, but R2 is now connected through R1. This means that all measurements taken by R2 must hop through R1 before making it back to the gateway. In addition, R1 is now not only responsible for sending its own measurement data, but also the R2 data. This configuration is considered a worst case 1-hop system, as R2 and R1 both have the possibility of meshing through a router that is connected to the gateway. NI recommends configuring your system for no more than three hops. Configuring multiple nodes as routers and placing them within close proximity introduces the possibility that your system could mesh inefficiently. Figure 4 shows how a system could mesh efficiently, yet also have the possibility of meshing inefficiently.




Figure 4.  Same Topology - Two Ways to Mesh (Inefficient vs. Efficient)

This network can be improved with two separate techniques:
  1. Convert some routers to end nodes.
  2. Set up the network to prevent the routers from being in range of each other (spatially separated by distance, or introducing objects that increase radio interference such as buildings).
Another advantage of the mesh network is the ability to extend the distance of the end measurement from the wired gateway. By placing mesh routers throughout the space where you wish to acquire signals, you can expand the area and distance across which measurement data can be acquired and sent. In an outdoor environment with line of sight, a single communication hop can extend up to 300m.  NI recommends no more than three hops from any device to the gateway, meaning you can extend your measurements up to 900m from the gateway.



Figure 5.  Using Router Nodes to Extend Network Distance

Configuring Your NI WSN System

As discussed in the Mesh Networking section, creating a reliable and efficient wireless sensor network requires an understanding of the physical environment the network will reside in, as well as an understanding of the expected meshing configuration. Additionally, the following consideration needs to be taken into account: parent devices (routers and gateways) can only have a maximum of eight end nodes connected to them at a given time.  This means that to achieve the maximum density of 36 nodes per gateway, you must include router nodes in your topology.  
If you wish to implement a star topology, in which no routers are utilized, you can only connect eight end nodes to your gateway, as seen in Figure 6.



Figure 6.  Maximum of Eight End Nodes in a Star Topology

To achieve the 36-node limit for WSN gateways, you can introduce router nodes into your system.  Architecting your system will depend on your application, but the two most common 36-node mesh topologies can be seen below.  In the topology illustrated by Figure 7, measurement points can be scattered among a large area that is only 2 hops from the gateway.



Figure 7.  High-Density, Medium-Distance Mesh Topology Example

If distance is more important than measurement density in your application, you can architect a topology in which end nodes are three hops from the gateway, as seen in Figure 8.



Figure 8.  Medium-Density, High-Distance Mesh Topology Example

Keep in mind, however, that the 8:1 end node to parent ratio limit introduces a potential issue known as the stranded node problem. The stranded node problem exists when a node configured as an end node has the possibility of not being able to join a device. Figure 9 shows a network consisting of one gateway, two routers, and nine end nodes. 


Figure 9.  Mesh Topology Without Stranded Node

In this case, all nodes have properly meshed, and all nodes can communicate with the gateway. However, this network could potentially strand end nodes. Figure 10 shows another possible mesh of the same network.






Figure 10.  Mesh Topology With Stranded Node

In this mesh configuration, eight end nodes in range of both R1 and R2 join with R1. This leaves one end node stranded from the network. This can be corrected in the following two ways:
  1. Move the set of 8 end nodes to where they can only communicate with R2. This prevents them from
    possibly joining R1.
  2. Add an additional router that is in range of the single end node. This introduces the possibility of
    creating additional hops in the network, but also guarantees coverage of all end nodes.

Remove Virus From Laptop or Computer

How To Remove Virus From Laptop or Computer

There are many ways to remove viruses from a computer, some work and some don’t.  This guide is the best way to fix a computer virus.  All the tools used here are free for non-commercial use. Use this guide at your own risk. You are responsible for making sure your data is backed up.  This guide will help remove all rootkits, spyware, Trojans, viruses, malware, and other malicious software.  If you are not sure how to do some of the steps please feel free to contact PC Link Solutions and we can remove the virus remotely for $79

Step 1.
Boot up your computer in Safe Mode with Networking.  This can be accomplished by repeatable tapping the F8 key on your keyboard as soon as you hit the power button.  If you have an OEM computer like Dell or HP, other models too, soon as you see the Logo show up on your monitor; start hitting F8 until you see Advance Boot Options.  Once you see Advance Boot Options, use the arrow keys to move up and down to select Safe Mode with Networking.  If you use Windows XP select Yes when it asks you if you want to be in Safe Mode.

Step 2.
Navigate to a website by opening up Internet Explorer (or other web browser) and download a tool called ComboFix.  If you can’t open up Internet Explorer hold down the Windows Key (the key with a flag on it by the ctrl and alt button) and press the letter R once.  This will open up a box for you to type in a command or web address.  Type in http://www.bleepingcomputer.com/download/anti-virus/combofix and click on the ComboFix Download Link, which is the first mirror.  ComboFix is a very powerful tool and will remove Rootkits as well as other viruses and malicious software.  It will also fix a lot of problems the virus caused, such as hiding all your icons and documents.
Steps to running ComboFix
1.Click OK if you see a message about real time scanner, you’ll get a 2nd message about real time scanner so click OK to that as well.
2.Combo Fix will attempt to back up the registry.  Click no if you see a prompt to download Windows Recovery Console
3.Combo Fix will start scanning to remove viruses, let this finish it can take anywhere from 5mins to all night.  Usually only lasts about 20-30 minutes for the entire process.  It has around 50 phases so let it finish and let it automatically reboot your computer or laptop.
4.If Combo Fix detects a root kit it will let you know.  It will prompt you twice letting you know about the rootkit then saying Combo Fix will automatically reboot. DO NOT REBOOT THE COMPUTER if this comes up.  It needs to reboot itself.  Combo Fix will then reboot the computer and run a 2nd time.  Let Combo Fix run and do its job.
5.The final stage in Combo Fix is preparing the log report.  Make sure to let Combo Fix do this before using any programs or doing anything with your computer.  I’ve seen it take 2 hours to complete a report before so it could take a while, but usually only takes about 10 minutes.
6.You don’t need to do anything with the report, but it lists everything Combo Fix did.
7.After the log is done reboot the computer and go back into Safe Mode with networking.
Step 2.
The 2nd tool in the arsenal of removing malicious software, viruses and the like is Malwarebytes.  Download this tool from http://www.malwarebytes.org/ You don’t have to pay for it, but they do offer a subscription plan which will protect your computer in the future from getting viruses, so you may want to purchase it.  It can run alongside your antivirus software.  Make sure Malwarebytes is updated and you can do a full scan.  The full scan can take anywhere from 5 minutes to 5 hours, just depends on how fast your computer is and how much stuff you have to scan.  Once the scan is complete click View Results, then RIGHT-CLICK and do CHECK ALL.  This will make sure all items are checked.  Then click Remove Selected.  This will remove all the viruses it found.  After it removed the viruses you can reboot the machine to finish the process.

Step 3.
The next step is to run Super Anti-Spyware, this will also remove malicious software, similar to Malwarebytes, but it can find and remove things other programs can’t, so it’s a good idea to run this tool.  It can be found at http://www.superantispyware.com/ You will also want to run a full scan, then remove any objects it finds.  You can purchase the product which will keep your system protected alongside a good antivirus program.  Once the scan is complete and objects are removed it should prompt you to reboot the computer, so go ahead and reboot the computer.

Step 4.
Remove hijacked URL’s with hijackthis.  Hijackthis is a free tool and can be found http://free.antivirus.com/hijackthis/ Go ahead and do a system scan with log file.  Copy the contents out of the log file and paste them into this web address http://hijackthis.de/ then click analyze.  Remove any objects that have a RED X and review the objects that have a YELLOW X to see if it’s a program you use.

Step 5.
Run CCleaner  which can be found here and clean out temporary files to help speed up your computer.  Also do a registry clean, and fix objects it finds.  Make sure to ALWAYS BACKUP the registry when doing a Registry clean.  CCleaner will prompt you to do this.  After this is done reboot your machine and your virus Free!

 

Speed Up Your Web Browsing

Even in a world where high-speed internet is just a tall house blend away, anyone can get stuck with a slow or uncertain connection at home, in the office, or at the worst possible time while traveling. There are, however, measures anyone can take to ensure they're getting the most information and functionality they can when crunched for time or pressed for bandwidth—or if you just don't like waiting for things while online. We're offering up today 10 tweaks, downloads, and work-arounds for slow connections, slow computers, or just fast-minded people. Read on for the tips that might just save your life some night when 4 Kb/s is all you can muster

1. Use Secure, Automatic Passwords

Top 10 Ways to Speed Up Your Web Browsing

Auto-saving, auto-filling passwords have made their way into most every browser, but, by default, they're only as secure as your ability to keep someone away from your keyboard. If your browser offers a master password option, use it—in Firefox, it's the only barrier between you and a single button unveiling all your passwords to snoopy friends or nefarious interlopers. Of course, if you're using the same weak password across all your site logins, you're just asking to have somebody get into your email, private social messages, and other private data. Using a secure password system can fix that. If you're using multiple browsers across different systems, you can keep your time-saving password fillers synced with Dropbox, or take care of bookmarks as well with the (Firefox only) Foxmarks. Whether you need to get your browsing done quick, or you're just a fan of streamlined web surfing, what do you use to get more out of your time online? Tell us your own tips and tricks in the comments.


2. Set up OpenDNS on your browser or router

Top 10 Ways to Speed Up Your Web Browsing

If you're a customer of Time Warner, Verizon, or most any commercial internet provider, you'll occasionally end up at an ad-filled page whenever you typo your way to a non-existent page, and how quickly your browser knows where to find its data depends on their heavily-taxed servers. You can do a lot better with OpenDNS, a free service that can speed up your page connections, open pages from keyword shortcuts, serve as a parental filter, and avoid spam-y "no site here" pages. The service provides detailed how-to instructions for both individual computers and routers, so it's definitely worth at least a try.


3. Block Flash and/or JavaScript

Top 10 Ways to Speed Up Your Web Browsing


Our side editor suggested this move after spending a week on a dial-up connection. Firefox users have it easy: Install the Adblock Plus and Flashblock extensions, and sites bogged down mostly by unnecessary Flash and huge display ads will come through a lot quicker. If you're cool with tweaking your router a bit, you can set up universal ad-blocking through it with the Tomato firmware, or use a solution specific to Chrome, on Internet Explorer through the Toggle Flash add-on or IE7Pro plug-in, and even on your iPhone or iPod touch. Lifehacker is, of course, an ad-supported site, and we'd ask that you use such tools only when bandwidth or time are at a serious premium, or for sites that bludgeon you over the head with lowering interest rates, free laptops, and the like.


4. Swap heavy sites for RSS feeds and mobile versions

Top 10 Ways to Speed Up Your Web Browsing

Here's a not-so-secret tip about your Lifehacker editors—we couldn't possibly read the full version of every blog, news site, and aggregation site we pull our post material from every day. RSS feeds are this blog's bread and butter, and they're great for getting a lot of reading done in a short amount of time. We're split fairly evenly between the Google Reader webapp and NetNewsWire/NewsGator's desktop clients, but both are a great way to catch up on your regular web reading with a minimum of bandwidth, or no connection whatsoever. Along those lines, you can run any site that's chock full of text-y news through the Google Mobilizer for a version that's fast enough for a mobile phone, and very fast on a desktop.

5. Throttle your home wireless network

Top 10 Ways to Speed Up Your Web Browsing

Your home's wireless router doesn't have to be a neutral observer while watching your XBox, BitTorrent downloads, multiple laptops, and other web-connected apps and gear fight it out for a finite amount of bandwidth. Many routers let you negotiate connection rate treaties using Quality of Service settings—and those that don't can often be made to do so by installing DD-WRT or Tomato. The end result? You can let World of Warcraft run rampant in the evenings, set BitTorrent free in the dead of night, and keep your browser unthrottled during the day. Check out Adam's guide to ensuring a fast net connection when you need it for the geeky details.


6. Bump up your cache size (and make other configuration tweaks)

Top 10 Ways to Speed Up Your Web Browsing

Another set of revelations from living in dial-up land, the configuration options that you'd normally never touch are serious life-savers if you're on weak Wi-Fi, an older, slower system, or just tired of watching your mouse cursor do it's "waiting" animation over and over. Upping your cache size definitely speeds up your back button action and speeds up repetitive banners and graphics. Sites that really don't need graphics to work can be disabled with site-by-site exceptions in Firefox, and these days, any browser can open sites you might need to wait on in a new tab while you keep grooving in another. For getting something done on Google Docs or Zoho, reading feeds in Google Reader, or managing tasks in Remember the Milk, there's Google's Gears extension to work offline and connect only when you need to sync your data.


7. Make Faster, Fool-Proof Downloads with Down Them All

Top 10 Ways to Speed Up Your Web Browsing

Right-clicking a picture or link, selecting "Save Link As," choosing a download spot—it gets real old, real fast, especially if you try to do it on every picture in a Flickr set, every MP3 on a music blog, or anywhere else you do your downloading. Free Firefox extension DownThemAll, our readers' favorite download manager, makes it easy to do all those things, or set up smart filters and settings to make any page with tons of files easy to navigate. For a good guide on setting that up, try our tutorial on supercharging your Firefox downloads with DownThemAll.

8. Use Safari or Opera

Top 10 Ways to Speed Up Your Web Browsing

Look at nearly any web site's traffic statistics, and Apple's Safari and the Norse-made Opera browser are just a sliver compared to how many use Internet Explorer and Firefox. In our own browser speed tests, though, we found Opera and Safari to be the champs at loading web pages and rendering JavaScript and CSS templates, respectively. There are lots of reasons to use Firefox (extensions! theming! Greasemonkey!) and Internet Explorer (some sites only work with it!), but if your browser is mainly just a window on the web, consider keeping a copy of Safari, Opera, or the well-rounded Google Chrome on hand for speeding up your site visits.


9. Use TraceMonkey in Firefox 3.1

Top 10 Ways to Speed Up Your Web Browsing

More and more developers and established web sites are moving their services online and using JavaScript to create interactive web pages these days. So when you're browsing Flickr, MySpace/Facebook, or nearly anything made by Google, as a few examples, the speed at which your browser runs all the developers' code can matter a lot. For more responsive pages, it's hard to beat the mind-blowing speed of TraceMonkey, the new JavaScript engine for Firefox 3.1. Mozilla offers nightly builds of TraceMonkey-enabled Firefox 3.1 (called "Minefield" when you run it, because it can be a bit, well, buggy), but Windows users can also test drive 3.1 without harming their existing Firefox. Of course, depending on who you ask (and which test you run), Google Chrome's V8 and the brand-new script engine in WebKit, the foundation of Safari, are potentially faster. In any case, your current browser probably isn't this fast, so taking these speed demons for a test drive can't hurt.


10. Use Google to read HTML copies of huge documents

Ah, Adobe Acrobat. It's free and universally used to view documents exactly as they'd print, but few things bottleneck a browsing session like an 8MB PDF file, especially if your browser crashes before showing it. But we can all benefit from Google's zeal to index everything on Earth. If you've got a Google Docs or Gmail account, uploading or emailing a PDF gives you an option to view its as an HTML, which is going to come through a lot faster. The same holds for PowerPoint presentations, Word 2007 .docx files, and nearly any document you can find in Google search. One of those work-arounds that's so simple, you'll be glad when you remember it when you're trying to jam through that presentation on a terrible hotel Wi-Fi connection.

make a computer faster

By following a few simple guidelines, you can maintain your computer, help increase its speed, and help keep it running smoothly. This article discusses how to use the tools available in Windows 8, Windows 7, Windows Vista, and Windows XP Service Pack 3 to help make your computer faster, maintain your computer efficiently, and help safeguard your privacy when you're online.
Note: Some of the tools mentioned in this article require you to be logged on as an administrator. If you aren't logged on as an administrator, you can only change settings that apply to your user account.

1. Remove spyware, and help protect your computer from viruses

Spyware collects personal information without asking for permission. From the websites you visit to user names and passwords, spyware can put you and your confidential information at risk. In addition to compromising your privacy, spyware can hamper your computer's performance. Fortunately, there are a couple of easy ways to combat spyware.
Download Microsoft Security Essentials for free to help guard your system from viruses, spyware, adware, and other malicious software (also known as malware). Microsoft Security Essentials acts as a spyware removal tool and includes automatic updates to help keep your system protected from emerging threats.
The Microsoft Windows Malicious Software Removal Tool, also free, checks computers running Windows 8, Windows 7, Windows Vista, Windows XP, Windows 2000, Windows Server 2012, Windows Server 2008, and Windows Server 2003 for infections by specific, prevalent malicious software, including Folstart, Phorpiex, Weelsof, Blaster, Sasser, and Mydoom. It helps remove any detected infection or malware.

2. Free up disk space

The Disk Cleanup tool helps you to free up space on your hard disk to improve the performance of your computer. The tool identifies files that you can safely delete and lets you choose to delete some, all, or none of the identified files.
Use Disk Cleanup to:
  • Remove temporary Internet files.
  • Delete downloaded program files, such as Microsoft ActiveX controls and Java applets.
  • Empty the Recycle Bin.
  • Remove Windows temporary files, such as error reports.
  • Delete optional Windows components that you don't use.
  • Delete installed programs that you no longer use.
  • Remove unused restore points and shadow copies from System Restore.
  • Delete system files (Windows 8).
Tip: Typically, temporary Internet files take the most amount of space because the browser caches each page you visit for faster access later.
To use Disk Cleanup:

Windows 8 users

Windows 7 users

Windows Vista users

Windows XP users


3. Speed up access to data

Disk fragmentation slows the overall performance of your system. When files are fragmented, the computer must search the hard disk as a file is opened (to piece it back together). The response time can be significantly longer.
Optimize Drives (Windows 8) and Disk Defragmenter (sometimes shortened to Defrag by users) are Windows utilities that consolidate fragmented files and folders on your computer's hard disk so that each occupies a single space on the disk. With your files stored neatly end to end, without fragmentation, reading and writing to the disk speeds up.
When to run Optimize Drives or Disk Defragmenter
In addition to running these utilities at regular intervals (weekly is optimal), there are other times you should run it, too, such as when:
  • You add a large number of files.
  • Your free disk space totals 15 percent or less.
  • You install new programs or a new version of the Windows operating system.
To use Optimize Drives:
  1. Open Optimize Drives by swiping in from the right edge of the screen, tapping Search (or if you're using a mouse, pointing to the upper-right corner of the screen, moving the mouse pointer down, and then clicking Search), entering Defragment in the search box, tapping or clicking Settings, and then tapping or clicking Defragment and optimize your drives.
  2. Under Status, tap or click the drive you want to optimize. (The Media type column tells you what type of drive you're optimizing.)
  3. To determine if the drive needs to be optimized, tap or click Analyze. You might be asked for an admin password or to confirm your choice.
    After Windows is finished analyzing the drive, check the Current status column to see whether you need to optimize the drive. If the drive is more than 10% fragmented, you should optimize the drive now.
  4. Tap or click Optimize. You might be asked for an admin password or to confirm your choice.
    Optimizing a drive might take anywhere from several minutes to a few hours to finish, depending on the size of the drive and degree of optimization needed. You can still use your PC during the optimization process.
Notes
  • If the drive is being used by another program, or is formatted using a file system other than NTFS, FAT, or FAT32, it can't be optimized.
  • Network drives can't be optimized.
  • If a drive isn't appearing in Optimize Drives, it might be because it contains an error. Try to repair the drive first, then return to Optimize Drives to try again.
Additional information and instruction to optimize your hard drive for Windows 8 is available.
To use Disk Defragmenter:

Windows 7 users

Windows Vista users

In this version of Windows, Disk Defragmenter is set to run every week, so you don't have to remember to run it and you don't need to do anything else. However, you can change how often Disk Defragmenter runs, and at what time of day. To change the schedule:
  1. Click Modify schedule....
  2. In the Disk Defragmenter: Modify Schedule dialog box, choose how often, which day, and at what time of day you want defragmentation to occur, and then click OK.
  3. Click OK again.
To manually open Disk Defragmenter:
  1. Open Disk Defragmenter by clicking the Start button, clicking All Programs, clicking Accessories, clicking System Tools, and then clicking Disk Defragmenter. If you are prompted for an administrator password or confirmation, type the password or provide confirmation.
  2. Click Defragment Now.
Disk Defragmenter may take from several minutes to a few hours to finish, depending on the size and degree of fragmentation of your hard disk. You can still use your computer during the defragmentation process.

Windows XP users

Running Optimize Drives, Disk Cleanup, and Disk Defragmenter on a regular basis is a proven way to help keep your computer running quickly and efficiently. If you'd like to learn how to schedule these tools and others to run automatically, please read Speed up your PC: Automate your computer maintenance schedule. Windows 8 users should read Improve performance by optimizing your hard drive.

4. Detect and repair disk errors

In addition to running Optimize Drives, Disk Cleanup, and Disk Defragmenter to optimize the performance of your computer, you can check the integrity of the files stored on your hard disk by running the Error Checking utility.
As you use your hard drive, it can develop bad sectors. Bad sectors slow down hard disk performance and sometimes make data writing (such as file saving) difficult or even impossible. The Error Checking utility scans the hard drive for bad sectors and scans for file system errors to see whether certain files or folders are misplaced.
If you use your computer daily, you should run this utility once a week to help prevent data loss.

Run the Error Checking utility:


5. Learn about ReadyBoost

If you're using Windows 8, Windows 7, or Windows Vista, you can use ReadyBoost to speed up your system. A new concept in adding memory to a system, it allows you to use non-volatile flash memory—like a USB flash drive or a memory card—to improve performance without having to add additional memory. With Windows 8, if you have a storage device that will work with ReadyBoost, you’ll see an option to use ReadyBoost when you plug the device in to your PC.
  • Learn more about ReadyBoost in Windows 7.
  • Learn more about ReadyBoost in Windows Vista.

6. Upgrade to Windows 8

If you try all the previous remedies and your computer still isn't as fast as you would like it to be, you may want to consider updating to Windows 8.
  • Download the Upgrade Assistant to find out if your computer can run Windows 8.
  • Download Windows 8 Pro.
  • Compare Windows 8 editions.
If the Windows 8 Upgrade Assistant determines that your computer can't run Windows 8 and you still have the need for speed, it might be time for a new computer. There are some great deals on new computers right now:
  • Shop for a Surface.
  • Shop for new desktop computers.
  • Shop for new laptop computers.

Wednesday, February 27, 2013

Firewalls

Introduction

Firewalls make it possible to filter the incoming and outgoing traffic that flows through a system. A firewall can use one or more sets of “rules” to inspect network packets as they come in or go out of network connections and either allows the traffic through or blocks it. The rules of a firewall can inspect one or more characteristics of the packets such as the protocol type, source or destination host address, and source or destination port.
Firewalls can enhance the security of a host or a network. They can be used to do one or more of the following:
  • Protect and insulate the applications, services, and machines of an internal network from unwanted traffic from the public Internet.
  • Limit or disable access from hosts of the internal network to services of the public Internet.
  • Support network address translation (NAT), which allows an internal network to use private IP addresses and share a single connection to the public Internet using either a single IP address or a shared pool of automatically assigned public addresses.
After reading this chapter, you will know:
  • How to define packet filtering rules.
  • The differences between the firewalls built into FreeBSD.
  • How to use and configure the PF firewall.
  • How to use and configure the IPFILTER firewall.
  • How to use and configure the IPFW firewall.
Before reading this chapter, you should:
  • Understand basic FreeBSD and Internet concepts.

    Firewall Concepts

    A firewall ruleset can be either “exclusive” or “inclusive”. An exclusive firewall allows all traffic through except for the traffic matching the ruleset. An inclusive firewall does the reverse as it only allows traffic matching the rules through and blocks everything else.
    An inclusive firewall offers better control of the outgoing traffic, making it a better choice for systems that offer services to the public Internet. It also controls the type of traffic originating from the public Internet that can gain access to a private network. All traffic that does not match the rules is blocked and logged. Inclusive firewalls are generally safer than exclusive firewalls because they significantly reduce the risk of allowing unwanted traffic.
    Note: Unless noted otherwise, all configuration and example rulesets in this chapter create inclusive firewall rulesets.
    Security can be tightened further using a “stateful firewall”. This type of firewall keeps track of open connections and only allows traffic which either matches an existing connection or opens a new, allowed connection. The disadvantage of a stateful firewall is that it can be vulnerable to Denial of Service (DoS) attacks if a lot of new connections are opened very fast. Most firewalls use a combination of stateful and non-stateful behavior.


    Firewall Packages

    FreeBSD has three firewalls built into the base system: IPFILTER, also known as IPF, IPFIREWALL, also known as IPFW, and PF). FreeBSD also provides two traffic shapers for controlling bandwidth usage: altq(4) and dummynet(4). Dummynet has traditionally been closely tied with IPFW, and ALTQ with PF. Each firewall uses rules to control the access of packets to and from a FreeBSD system, although they go about it in different ways and each has a different rule syntax.
    FreeBSD provides multiple firewalls in order to meet the different requirements and preferences for a wide variety of users. Each user should evaluate which firewall best meets their needs.
    Since all firewalls are based on inspecting the values of selected packet control fields, the creator of the firewall ruleset must have an understanding of how TCP/IP works, what the different values in the packet control fields are, and how these values are used in a normal session conversation. For a good introduction, refer to Daryl's TCP/IP Primer

    .The IPFILTER (IPF) Firewall

    IPFILTER is a cross-platform, open source firewall which has been ported to FreeBSD, NetBSD, OpenBSD, SunOS™, HP/UX, and Solaris™ operating systems. 

    IPFILTER is based on a kernel-side firewall and NAT mechanism that can be controlled and monitored by userland interface programs. The firewall rules can be set or deleted using ipf(8). The NAT rules can be set or deleted using ipnat(8). Run-time statistics for the kernel parts of IPFILTER can be printed using ipfstat(8). To log IPFILTER actions to the system log files, use ipmon(8).
    IPF was originally written using a rule processing logic of “the last matching rule wins” and only used stateless rules. Over time, IPF has been enhanced to include a “quick” option and a stateful “keep state” option which modernized the rules processing logic. IPF's official documentation covers only the legacy rule coding parameters and rule file processing logic and the modernized functions are only included as additional options.
    The instructions contained in this section are based on using rules that contain “quick” and “keep state” as these provide the basic framework for configuring an inclusive firewall ruleset.
    For a detailed explanation of the legacy rules processing method, refer to http://www.munk.me.uk/ipf/ipf-howto.html and http://coombs.anu.edu.au/~avalon/ip-filter.html.
    The IPF FAQ is at http://www.phildev.net/ipf/index.html.
    A searchable archive of the IPFilter mailing list is available at http://marc.theaimsgroup.com/?l=ipfilter.


    Enabling IPF

    IPF is included in the basic FreeBSD install as a kernel loadable module. The system will dynamically load this module at boot time when ipfilter_enable="YES" is added to rc.conf. The module enables logging and default pass all. To change the default to block all, add a block all rule at the end of the ruleset.


    Kernel Options

    For users who prefer to statically compile IPF support into a custom kernel, the following IPF option statements, listed in /usr/src/sys/conf/NOTES, are available:
    options IPFILTER
    options IPFILTER_LOG
    options IPFILTER_DEFAULT_BLOCK
    
    options IPFILTER enables support for the “IPFILTER” firewall.
    options IPFILTER_LOG enables IPF logging using the ipl packet logging pseudo—device for every rule that has the log keyword.
    options IPFILTER_DEFAULT_BLOCK changes the default behavior so that any packet not matching a firewall pass rule gets blocked.
    These settings will take effect only after installing a kernel that has been built with the above options set.


    Available rc.conf Options

    To activate IPF at boot time, the following statements need to be added to /etc/rc.conf:
    ipfilter_enable="YES"             # Start ipf firewall
    ipfilter_rules="/etc/ipf.rules"   # loads rules definition text file
    ipmon_enable="YES"                # Start IP monitor log
    ipmon_flags="-Ds"                 # D = start as daemon
                                      # s = log to syslog
                                      # v = log tcp window, ack, seq
                                      # n = map IP & port to names
    
    If there is a LAN behind the firewall that uses the reserved private IP address ranges, the following lines have to be added to enable NAT functionality:
    gateway_enable="YES"              # Enable as LAN gateway
    ipnat_enable="YES"                # Start ipnat function
    ipnat_rules="/etc/ipnat.rules"    # rules definition file for ipnat 
     
     
     

    IPF

    To load the ruleset file, use ipf(8). Custom rules are normally placed in a file, and the following command can be used to replace the currently running firewall rules:
    # ipf -Fa -f /etc/ipf.rules -Fa flushes all the internal rules tables.
    -f specifies the file containing the rules to load.
    This provides the ability to make changes to a custom rules file, run the above IPF command, and thus update the running firewall with a fresh copy of the rules without having to reboot the system. This method is convenient for testing new rules as the procedure can be executed as many times as needed.
    Refer to ipf(8) for details on the other flags available with this command.
    ipf(8) expects the rules file to be a standard text file. It will not accept a rules file written as a script with symbolic substitution.
    There is a way to build IPF rules that utilize the power of script symbolic substitution. For more information, see .


    IPFSTAT

    The default behavior of ipfstat(8) is to retrieve and display the totals of the accumulated statistics gathered by applying the rules against packets going in and out of the firewall since it was last started, or since the last time the accumulators were reset to zero using ipf -Z.
    Refer to ipfstat(8) for details.
    The default ipfstat(8) output will look something like this:
    input packets: blocked 99286 passed 1255609 nomatch 14686 counted 0
     output packets: blocked 4200 passed 1284345 nomatch 14687 counted 0
     input packets logged: blocked 99286 passed 0
     output packets logged: blocked 0 passed 0
     packets logged: input 0 output 0
     log failures: input 3898 output 0
     fragment state(in): kept 0 lost 0
     fragment state(out): kept 0 lost 0
     packet state(in): kept 169364 lost 0
     packet state(out): kept 431395 lost 0
     ICMP replies: 0 TCP RSTs sent: 0
     Result cache hits(in): 1215208 (out): 1098963
     IN Pullups succeeded: 2 failed: 0
     OUT Pullups succeeded: 0 failed: 0
     Fastroute successes: 0 failures: 0
     TCP cksum fails(in): 0 (out): 0
     Packet log flags set: (0)
    
    When supplied with either -i for inbound or -o for outbound, the command will retrieve and display the appropriate list of filter rules currently installed and in use by the kernel.
    ipfstat -in displays the inbound internal rules table with rule numbers.
    ipfstat -on displays the outbound internal rules table with rule numbers.
    The output will look something like this:
    @1 pass out on xl0 from any to any
    @2 block out on dc0 from any to any
    @3 pass out quick on dc0 proto tcp/udp from any to any keep state
    
    ipfstat -ih displays the inbound internal rules table, prefixing each rule with a count of how many times the rule was matched.
    ipfstat -oh displays the outbound internal rules table, prefixing each rule with a count of how many times the rule was matched.
    The output will look something like this:
    2451423 pass out on xl0 from any to any
    354727 block out on dc0 from any to any
    430918 pass out quick on dc0 proto tcp/udp from any to any keep state
    
    One of the most important options of ipfstat is -t which displays the state table in a way similar to how top(1) shows the FreeBSD running process table. When a firewall is under attack, this function provides the ability to identify and see the attacking packets. The optional sub-flags give the ability to select the destination or source IP, port, or protocol to be monitored in real time. Refer to ipfstat(8) for details.

     

    IPMON

    In order for ipmon to work properly, the kernel option IPFILTER_LOG must be turned on. This command has two different modes. Native mode is the default mode when the command is used without -D.
    Daemon mode provides a continuous system log file so that logging of past events may be reviewed. FreeBSD has a built in facility to automatically rotate system logs. This is why outputting the log information to syslogd(8) is better than the default of outputting to a regular file. The default rc.conf ipmon_flags statement uses -Ds:
    ipmon_flags="-Ds" # D = start as daemon
                      # s = log to syslog
                      # v = log tcp window, ack, seq
                      # n = map IP & port to names
    
    Logging provides the ability to review, after the fact, information such as which packets were dropped, what addresses they came from and where they were going. These can all provide a significant edge in tracking down attackers.
    Even with the logging facility enabled, IPF will not generate any rule logging by default. The firewall administrator decides which rules in the ruleset should be logged and adds the log keyword to those rules. Normally, only deny rules are logged.
    It is customary to include a “default deny everything” rule with the log keyword included as the last rule in the ruleset. This makes it possible to see all the packets that did not match any of the rules in the ruleset.

    IPMON Logging

    syslogd(8) uses its own method for segregation of log data. It uses groupings called “facility” and “level”. By default, IPMON in -Ds mode uses local0 as the “facility” name. The following levels can be used to further segregate the logged data:
    LOG_INFO - packets logged using the "log" keyword as the action rather than pass or block.
    LOG_NOTICE - packets logged which are also passed
    LOG_WARNING - packets logged which are also blocked
    LOG_ERR - packets which have been logged and which can be considered short
    
    In order to setup IPFILTER to log all data to /var/log/ipfilter.log, first create the empty file:
    # touch /var/log/ipfilter.log
    
    syslogd(8) is controlled by definition statements in /etc/syslog.conf. This file offers considerable flexibility in how syslog will deal with system messages issued by software applications like IPF.
    To write all logged messages to the specified file, add the following statement to /etc/syslog.conf:
    local0.* /var/log/ipfilter.log
    
    To activate the changes and instruct syslogd(8) to read the modified /etc/syslog.conf, run service syslogd reload.
    Do not forget to change /etc/newsyslog.conf to rotate the new log file.

    The Format of Logged Messages

    Messages generated by ipmon consist of data fields separated by white space. Fields common to all messages are:
  • The date of packet receipt.
  • The time of packet receipt. This is in the form HH:MM:SS.F, for hours, minutes, seconds, and fractions of a second.
  • The name of the interface that processed the packet.
  • The group and rule number of the rule in the format @0:17.
These can be viewed with ipfstat -in.
  1. The action: p for passed, b for blocked, S for a short packet, n did not match any rules, and L for a log rule. The order of precedence in showing flags is: S, p, b, n, L. A capital P or B means that the packet has been logged due to a global logging setting, not a particular rule.
  2. The addresses written as three fields: the source address and port separated by a comma, the -> symbol, and the destination address and port. For example: 209.53.17.22,80 -> 198.73.220.17,1722.
  3. PR followed by the protocol name or number: for example, PR tcp.
  4. len followed by the header length and total length of the packet: for example, len 20 40.
If the packet is a TCP packet, there will be an additional field starting with a hyphen followed by letters corresponding to any flags that were set. Refer to ipf(5) for a list of letters and their flags.
If the packet is an ICMP packet, there will be two fields at the end: the first always being “ICMP” and the next being the ICMP message and sub-message type, separated by a slash. For example: ICMP 3/3 for a port unreachable message.


Building the Rule Script with Symbolic Substitution

Some experienced IPF users create a file containing the rules and code them in a manner compatible with running them as a script with symbolic substitution. The major benefit of doing this is that only the value associated with the symbolic name needs to be changed, and when the script is run all the rules containing the symbolic name will have the value substituted in the rules. Being a script, symbolic substitution can be used to code frequently used values and substitute them in multiple rules. This can be seen in the following example.
The script syntax used here is compatible with the sh(1), csh(1), and tcsh(1) shells.
Symbolic substitution fields are prefixed with a $.
Symbolic fields do not have the $ prefix.
The value to populate the symbolic field must be enclosed between double quotes (").
Start the rule file with something like this:
############# Start of IPF rules script ########################

oif="dc0"            # name of the outbound interface
odns="192.0.2.11"    # ISP's DNS server IP address
myip="192.0.2.7"     # my static IP address from ISP
ks="keep state"
fks="flags S keep state"

# You can choose between building /etc/ipf.rules file
# from this script or running this script "as is".
#
# Uncomment only one line and comment out another.
#
# 1) This can be used for building /etc/ipf.rules:
#cat > /etc/ipf.rules << EOF
#
# 2) This can be used to run script "as is":
/sbin/ipf -Fa -f - << EOF

# Allow out access to my ISP's Domain name server.
pass out quick on $oif proto tcp from any to $odns port = 53 $fks
pass out quick on $oif proto udp from any to $odns port = 53 $ks

# Allow out non-secure standard www function
pass out quick on $oif proto tcp from $myip to any port = 80 $fks

# Allow out secure www function https over TLS SSL
pass out quick on $oif proto tcp from $myip to any port = 443 $fks
EOF
################## End of IPF rules script ########################
The rules are not important in this example as it instead focuses on how the symbolic substitution fields are populated. If this example was in a file named /etc/ipf.rules.script, these rules could be reloaded by running:
# sh /etc/ipf.rules.script
There is one problem with using a rules file with embedded symbolics: IPF does not understand symbolic substitution, and cannot read such scripts directly.
This script can be used in one of two ways:
  • Uncomment the line that begins with cat, and comment out the line that begins with /sbin/ipf. Place ipfilter_enable="YES" into /etc/rc.conf, and run the script once after each modification to create or update /etc/ipf.rules.
  • Disable IPFILTER in the system startup scripts by adding ipfilter_enable="NO"to /etc/rc.conf.
    Then, add a script like the following to /usr/local/etc/rc.d/. The script should have an obvious name like ipf.loadrules.sh, where the .sh extension is mandatory.
    #!/bin/sh
    sh /etc/ipf.rules.script
    
    The permissions on this script file must be read, write, execute for owner root:
    # chmod 700 /usr/local/etc/rc.d/ipf.loadrules.sh
    
Now, when the system boots, the IPF rules will be loaded.

IPF Rulesets

A ruleset contains a group of IPF rules which pass or block packets based on the values contained in the packet. The bi-directional exchange of packets between hosts comprises a session conversation. The firewall ruleset processes both the packets arriving from the public Internet, as well as the packets produced by the system as a response to them. Each TCP/IP service is predefined by its protocol and listening port. Packets destined for a specific service originate from the source address using an unprivileged port and target the specific service port on the destination address. All the above parameters can be used as selection criteria to create rules which will pass or block services.
Warning: When working with the firewall rules, be very careful. Some configurations can lock the administrator out of the server. To be on the safe side, consider performing the initial firewall configuration from the local console rather than doing it remotely over ssh.

Rule Syntax

The rule syntax presented here has been simplified to only address the modern stateful rule context and “first matching rule wins” logic. For the complete legacy rule syntax, refer to ipf(8).
A # character is used to mark the start of a comment and may appear at the end of a rule line or on its own line. Blank lines are ignored.
Rules contain keywords which must be written in a specific order from left to right on the line. Keywords are identified in bold type. Some keywords have sub-options which may be keywords themselves and also include more sub-options. Each of the headings in the below syntax has a bold section header which expands on the content.
ACTION IN-OUT OPTIONS SELECTION STATEFUL PROTO SRC_ADDR,DST_ADDR OBJECT PORT_NUM TCP_FLAG STATEFUL
ACTION = block | pass
IN-OUT = in | out
OPTIONS = log | quick | on interface-name
SELECTION = proto value | source/destination IP | port = number | flags flag-value
PROTO = tcp/udp | udp | tcp | icmp
SRC_ADD,DST_ADDR = all | from object to object
OBJECT = IP address | any
PORT_NUM = port number
TCP_FLAG = S
STATEFUL = keep state

ACTION

The action keyword indicates what to do with the packet if it matches the rest of the filter rule. Each rule must have an action. The following actions are recognized:
block indicates that the packet should be dropped if the selection parameters match the packet.
pass indicates that the packet should exit the firewall if the selection parameters match the packet.

IN-OUT

A mandatory requirement is that each filter rule explicitly state which side of the I/O it is to be used on. The next keyword must be either in or out and one or the other has to be included or the rule will not pass syntax checks.
in means this rule is being applied against an inbound packet which has just been received on the interface facing the public Internet.
out means this rule is being applied against an outbound packet destined for the interface facing the public Internet.

OPTIONS

Note: These options must be used in the order shown here.
log indicates that the packet header will be written to the ipl(4) packet log pseudo-device if the selection parameters match the packet.
quick indicates that if the selection parameters match the packet, this rule will be the last rule checked, and no further processing of any following rules will occur for this packet.
on indicates the interface name to be incorporated into the selection parameters. Interface names are as displayed by ifconfig(8). Using this option, the rule will only match if the packet is going through that interface in the specified direction.
When a packet is logged, the headers of the packet are written to the ipl(4) packet logging pseudo-device. Immediately following the log keyword, the following qualifiers may be used in this order:
body indicates that the first 128 bytes of the packet contents will be logged after the headers.
first. If the log keyword is being used in conjunction with a keep state option, this option is recommended so that only the triggering packet is logged and not every packet which matches the stateful connection.

SELECTION

The keywords described in this section are used to describe attributes of the packet to be checked when determining whether or not rules match. There is a keyword subject, and it has sub-option keywords, one of which has to be selected. The following general-purpose attributes are provided for matching, and must be used in this order:

PROTO

proto is the subject keyword which must include one of its corresponding keyword sub-option values. The sub-option indicates a specific protocol to be matched against.
tcp/udp | udp | tcp | icmp or any protocol names found in /etc/protocols are recognized and may be used. The special protocol keyword tcp/udp may be used to match either a TCP or a UDP packet, and has been added as a convenience to save duplication of otherwise identical rules.

SRC_ADDR/DST_ADDR

The all keyword is equivalent to “from any to any” with no other match parameters.
from | to src to dst: the from and to keywords are used to match against IP addresses. Rules must specify both the source and destination parameters. any is a special keyword that matches any IP address. Examples include: from any to any, from 0.0.0.0/0 to any, from any to 0.0.0.0/0, from 0.0.0.0 to any, and from any to 0.0.0.0.
There is no way to match ranges of IP addresses which do not express themselves easily using the dotted numeric form / mask-length notation. The net-mgmt/ipcalc port may be used to ease the calculation. Additional information is available at the utility's web page: http://jodies.de/ipcalc.

PORT

If a port match is included, for either or both of source and destination, it is only applied to TCP and UDP packets. When composing port comparisons, either the service name from /etc/services or an integer port number may be used. When the port appears as part of the from object, it matches the source port number. When it appears as part of the to object, it matches the destination port number. An example usage is from any to any port = 80
Single port comparisons may be done in a number of ways, using a number of different comparison operators. Instead of the = shown in the example above, the following operators may be used: !=, <, >, <=, >=, eq, ne, lt, gt, le, and ge.
To specify port ranges, place the two port numbers between <> or ><

TCP_FLAG

Flags are only effective for TCP filtering. The letters represent one of the possible flags that can be matched against the TCP packet header.
The modernized rules processing logic uses the flags S parameter to identify the TCP session start request.

STATEFUL

keep state indicates that on a pass rule, any packets that match the rules selection parameters should activate the stateful filtering facility.

Stateful Filtering

Stateful filtering treats traffic as a bi-directional exchange of packets comprising a session. When activated, keep-state dynamically generates internal rules for each anticipated packet being exchanged during the session. It has sufficient matching capabilities to determine if a packet is valid for a session. Any packets that do not properly fit the session template are automatically rejected.
IPF stateful filtering will also allow ICMP packets related to an existing TCP or UDP session. So, if an ICMP type 3 code 4 packet is a response in a session started by a keep state rule, it will automatically be allowed. Any packet that IPF can be certain is part of an active session, even if it is a different protocol, will be allowed.
Packets destined to go out through the interface connected to the public Internet are first checked against the dynamic state table. If the packet matches the next expected packet comprising an active session conversation, it exits the firewall and the state of the session conversation flow is updated in the dynamic state table. Packets that do not belong to an already active session, are checked against the outbound ruleset.
Packets coming in from the interface connected to the public Internet are first checked against the dynamic state table. If the packet matches the next expected packet comprising an active session, it exits the firewall and the state of the session conversation flow is updated in the dynamic state table. Packets that do not belong to an already active session, are checked against the inbound ruleset.
When the session completes, it is removed from the dynamic state table.
Stateful filtering allows one to focus on blocking/passing new sessions. If the new session is passed, all its subsequent packets are allowed automatically and any impostor packets are automatically rejected. If a new session is blocked, none of its subsequent packets are allowed. Stateful filtering provides advanced matching abilities capable of defending against the flood of different attack methods employed by attackers.

Inclusive Ruleset Example

The following ruleset is an example of an inclusive type of firewall which only allows services matching pass rules and blocks all others by default. Network firewalls intended to protect other machines should have at least two interfaces, and are generally configured to trust the LAN and to not trust the public Internet. Alternatively, a host based firewall might be configured to protect only the system it is running on, and is appropriate for servers on an untrusted network or a desktop system not protected by firewall on the network.
FreeBSD uses interface lo0 and IP address 127.0.0.1 for internal communication within the operating system. The firewall rules must contain rules to allow free movement of these internally used packets.
The interface which faces the public Internet is the one specified in the rules that authorize and control access of the outbound and inbound connections.
In cases where one or more NICs are cabled to private network segments, those interfaces may require rules to allow packets originating from those LAN interfaces transit to each other or to the Internet.
The rules should be organized into three major sections: the trusted interfaces, then the public interface outbound, and lastly, the public untrusted interface inbound.
The rules in each of the public interface sections should have the most frequently matched rules placed before less commonly matched rules, with the last rule in the section blocking and logging all packets on that interface and direction.
The outbound section in the following ruleset only contains pass rules which uniquely identify the services that are authorized for public Internet access. All the rules use quick, on, proto, port, and keep state. The proto tcp rules include flag to identify the session start request as the triggering packet to activate the stateful facility.
The inbound section blocks undesirable packets first, for two different reasons. The first is that malicious packets may be partial matches for legitimate traffic. These packets have to be discarded rather than allowed, based on their partial matches against the allow rules. The second reason is that known and uninteresting rejects may be blocked silently, rather than being logged by the last rule in the section.
The ruleset should ensure that there is no response returned for any undesirable traffic. Invalid packets should be silently dropped so that the attacker has no knowledge if the packets reached the system. Rules that include a log first option, will only log the event the first time they are triggered. This option is included in the sample nmap OS fingerprint rule. The security/nmap utility is commonly used by attackers who attempt to identify the operating system of the server.
Any time there are logged messages on a rule with the log first option, ipfstat -hio should be executed to evaluate how many times the rule has been matched. A large number of matches usually indicates that the system is being flooded or is under attack.
To lookup unknown port numbers, refer to /etc/services. Alternatively, visit http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers and do a port number lookup to find the purpose of a particular port number.
Check out this link for port numbers used by Trojans http://www.sans.org/security-resources/idfaq/oddports.php.
The following ruleset creates an inclusive firewall ruleset which can be easily customized by commenting out pass rules for services that should not be authorized.
To avoid logging unwanted messages, add a block rule in the inbound section.
Change the dc0 interface name in every rule to the interface name that connects the system to the public Internet.
The following statements were added to /etc/ipf.rules:
#################################################################
# No restrictions on Inside LAN Interface for private network
# Not needed unless you have LAN
#################################################################

#pass out quick on xl0 all
#pass in quick on xl0 all

#################################################################
# No restrictions on Loopback Interface
#################################################################
pass in quick on lo0 all
pass out quick on lo0 all

#################################################################
# Interface facing Public Internet (Outbound Section)
# Match session start requests originating from behind the
# firewall on the private network
# or from this gateway server destined for the public Internet.
#################################################################

# Allow out access to my ISP's Domain name server.
# xxx must be the IP address of your ISP's DNS.
# Dup these lines if your ISP has more than one DNS server
# Get the IP addresses from /etc/resolv.conf file
pass out quick on dc0 proto tcp from any to xxx port = 53 flags S keep state
pass out quick on dc0 proto udp from any to xxx port = 53 keep state

# Allow out access to my ISP's DHCP server for cable or DSL networks.
# This rule is not needed for 'user ppp' type connection to the
# public Internet, so you can delete this whole group.
# Use the following rule and check log for IP address.
# Then put IP address in commented out rule & delete first rule
pass out log quick on dc0 proto udp from any to any port = 67 keep state
#pass out quick on dc0 proto udp from any to z.z.z.z port = 67 keep state


# Allow out non-secure standard www function
pass out quick on dc0 proto tcp from any to any port = 80 flags S keep state

# Allow out secure www function https over TLS SSL
pass out quick on dc0 proto tcp from any to any port = 443 flags S keep state

# Allow out send & get email function
pass out quick on dc0 proto tcp from any to any port = 110 flags S keep state
pass out quick on dc0 proto tcp from any to any port = 25 flags S keep state

# Allow out Time
pass out quick on dc0 proto tcp from any to any port = 37 flags S keep state

# Allow out nntp news
pass out quick on dc0 proto tcp from any to any port = 119 flags S keep state

# Allow out gateway & LAN users' non-secure FTP ( both passive & active modes)
# This function uses the IPNAT built in FTP proxy function coded in
# the nat rules file to make this single rule function correctly.
# If you want to use the pkg_add command to install application packages
# on your gateway system you need this rule.
pass out quick on dc0 proto tcp from any to any port = 21 flags S keep state

# Allow out ssh/sftp/scp (telnet/rlogin/FTP replacements)
# This function is using SSH (secure shell)
pass out quick on dc0 proto tcp from any to any port = 22 flags S keep state

# Allow out insecure Telnet
pass out quick on dc0 proto tcp from any to any port = 23 flags S keep state

# Allow out FreeBSD CVSup
pass out quick on dc0 proto tcp from any to any port = 5999 flags S keep state

# Allow out ping to public Internet
pass out quick on dc0 proto icmp from any to any icmp-type 8 keep state

# Allow out whois from LAN to public Internet
pass out quick on dc0 proto tcp from any to any port = 43 flags S keep state

# Block and log only the first occurrence of everything
# else that's trying to get out.
# This rule implements the default block
block out log first quick on dc0 all

#################################################################
# Interface facing Public Internet (Inbound Section)
# Match packets originating from the public Internet
# destined for this gateway server or the private network.
#################################################################

# Block all inbound traffic from non-routable or reserved address spaces
block in quick on dc0 from 192.168.0.0/16 to any    #RFC 1918 private IP
block in quick on dc0 from 172.16.0.0/12 to any     #RFC 1918 private IP
block in quick on dc0 from 10.0.0.0/8 to any        #RFC 1918 private IP
block in quick on dc0 from 127.0.0.0/8 to any       #loopback
block in quick on dc0 from 0.0.0.0/8 to any         #loopback
block in quick on dc0 from 169.254.0.0/16 to any    #DHCP auto-config
block in quick on dc0 from 192.0.2.0/24 to any      #reserved for docs
block in quick on dc0 from 204.152.64.0/23 to any   #Sun cluster interconnect
block in quick on dc0 from 224.0.0.0/3 to any       #Class D & E multicast

##### Block a bunch of different nasty things. ############
# That I do not want to see in the log

# Block frags
block in quick on dc0 all with frags

# Block short tcp packets
block in quick on dc0 proto tcp all with short

# block source routed packets
block in quick on dc0 all with opt lsrr
block in quick on dc0 all with opt ssrr

# Block nmap OS fingerprint attempts
# Log first occurrence of these so I can get their IP address
block in log first quick on dc0 proto tcp from any to any flags FUP

# Block anything with special options
block in quick on dc0 all with ipopts

# Block public pings
block in quick on dc0 proto icmp all icmp-type 8

# Block ident
block in quick on dc0 proto tcp from any to any port = 113

# Block all Netbios service. 137=name, 138=datagram, 139=session
# Netbios is MS/Windows sharing services.
# Block MS/Windows hosts2 name server requests 81
block in log first quick on dc0 proto tcp/udp from any to any port = 137
block in log first quick on dc0 proto tcp/udp from any to any port = 138
block in log first quick on dc0 proto tcp/udp from any to any port = 139
block in log first quick on dc0 proto tcp/udp from any to any port = 81

# Allow traffic in from ISP's DHCP server. This rule must contain
# the IP address of your ISP's DHCP server as it is the only
# authorized source to send this packet type. Only necessary for
# cable or DSL configurations. This rule is not needed for
# 'user ppp' type connection to the public Internet.
# This is the same IP address you captured and
# used in the outbound section.
pass in quick on dc0 proto udp from z.z.z.z to any port = 68 keep state

# Allow in standard www function because I have apache server
pass in quick on dc0 proto tcp from any to any port = 80 flags S keep state

# Allow in non-secure Telnet session from public Internet
# labeled non-secure because ID/PW passed over public Internet as clear text.
# Delete this sample group if you do not have telnet server enabled.
#pass in quick on dc0 proto tcp from any to any port = 23 flags S keep state

# Allow in secure FTP, Telnet, and SCP from public Internet
# This function is using SSH (secure shell)
pass in quick on dc0 proto tcp from any to any port = 22 flags S keep state

# Block and log only first occurrence of all remaining traffic
# coming into the firewall. The logging of only the first
# occurrence avoids filling up disk with Denial of Service logs.
# This rule implements the default block.
block in log first quick on dc0 all
################### End of rules file #####################################

NAT

NAT stands for Network Address Translation. In Linux®, NAT is called “IP Masquerading”. The IPF NAT function enables the private LAN behind the firewall to share a single ISP-assigned IP address, even if that address is dynamically assigned. NAT allows each computer in the LAN to have Internet access, without having to pay the ISP for multiple Internet accounts or IP addresses.
NAT will automatically translate the private LAN IP address for each system on the LAN to the single public IP address as packets exit the firewall bound for the public Internet. It also performs the reverse translation for returning packets.
According to RFC 1918, the following IP address ranges are reserved for private networks which will never be routed directly to the public Internet, and therefore are available for use with NAT:
  • 10.0.0.0/8.
  • 172.16.0.0/12.
  • 192.168.0.0/16.

IPNAT

NAT rules are loaded using ipnat. Typically, the NAT rules are stored in /etc/ipnat.rules. See ipnat(8) for details.
When the file containing the NAT rules is edited after NAT has been started, run ipnat with -CF to delete the internal in use NAT rules and flush the contents of the translation table of all active entries.
To reload the NAT rules, issue a command like this:
# ipnat -CF -f
   /etc/ipnat.rules
To display some NAT statistics, use this command:
# ipnat -s
To list the NAT table's current mappings, use this command:
# ipnat -l
To turn verbose mode on and display information relating to rule processing and active rules/table entries:
# ipnat -v

IPNAT Rules

NAT rules are flexible and can accomplish many different things to fit the needs of commercial and home users.
The rule syntax presented here has been simplified to what is most commonly used in a non-commercial environment. For a complete rule syntax description, refer to ipnat(5).
The syntax for a NAT rule looks like this:
map IF LAN_IP_RANGE -> PUBLIC_ADDRESS
The keyword map starts the rule.
Replace IF with the external interface.
The LAN_IP_RANGE is used by the internal clients use for IP Addressing. Usually, this is something like 192.168.1.0/24.
The PUBLIC_ADDRESS can either be the static external IP address or the special keyword 0/32 which uses the IP address assigned to IF.

How NAT Works

In IPF, when a packet arrives at the firewall from the LAN with a public destination, it passes through the outbound filter rules. NAT gets its turn at the packet and applies its rules top down, where the first matching rule wins. NAT tests each of its rules against the packet's interface name and source IP address. When a packet's interface name matches a NAT rule, the packet's source IP address in the private LAN is checked to see if it falls within the IP address range specified to the left of the arrow symbol on the NAT rule. On a match, the packet has its source IP address rewritten with the public IP address obtained by the 0/32 keyword. NAT posts an entry in its internal NAT table so when the packet returns from the public Internet it can be mapped back to its original private IP address and then passed to the filter rules for processing.

Enabling IPNAT

To enable IPNAT, add these statements to /etc/rc.conf.
To enable the machine to route traffic between interfaces:
gateway_enable="YES"
To start IPNAT automatically each time:
ipnat_enable="YES"
To specify where to load the IPNAT rules from:
ipnat_rules="/etc/ipnat.rules"

NAT for a Large LAN

For networks that have large numbers of systems on the LAN or networks with more than a single LAN, the process of funneling all those private IP addresses into a single public IP address becomes a resource problem that may cause problems with the same port numbers being used many times across many connections, causing collisions. There are two ways to relieve this resource problem.

Assigning Ports to Use

A normal NAT rule would look like:
map dc0 192.168.1.0/24 -> 0/32
In the above rule, the packet's source port is unchanged as the packet passes through IPNAT. By adding the portmap keyword, IPNAT can be directed to only use source ports in the specified range. For example, the following rule will tell IPNAT to modify the source port to be within the range shown:
map dc0 192.168.1.0/24 -> 0/32 portmap tcp/udp 20000:60000
Additionally, the auto keyword tells IPNAT to determine which ports are available for use:
map dc0 192.168.1.0/24 -> 0/32 portmap tcp/udp auto

Using a Pool of Public Addresses

In very large LANs there comes a point where there are just too many LAN addresses to fit into a single public address. If a block of public IP addresses is available, these addresses can be used as a “pool”, and IPNAT may pick one of the public IP addresses as packet addresses are mapped on their way out.
For example, instead of mapping all packets through a single public IP address:
map dc0 192.168.1.0/24 -> 204.134.75.1
A range of public IP addresses can be specified either with a netmask:
map dc0 192.168.1.0/24 -> 204.134.75.0/255.255.255.0
or using CIDR notation:
map dc0 192.168.1.0/24 -> 204.134.75.0/24

Port Redirection

A common practice is to have a web server, email server, database server, and DNS server each segregated to a different system on the LAN. In this case, the traffic from these servers still has to undergo NAT, but there has to be some way to direct the inbound traffic to the correct server. For example, a web server operating on LAN address 10.0.10.25 and using a single public IP address of 20.20.20.5, would use this rule:
rdr dc0 20.20.20.5/32 port 80 -> 10.0.10.25 port 80
or:
rdr dc0 0.0.0.0/0 port 80 -> 10.0.10.25 port 80
For a LAN DNS server on a private address of 10.0.10.33 that needs to receive public DNS requests:
rdr dc0 20.20.20.5/32 port 53 -> 10.0.10.33 port 53 udp

FTP and NAT

FTP has two modes: active mode and passive mode. The difference is in how the data channel is acquired. Passive mode is more secure as the data channel is acquired by the ordinal ftp session requester. For a good explanation of FTP and the different modes, see http://www.slacksite.com/other/ftp.html.

IPNAT Rules

IPNAT has a built in FTP proxy option which can be specified on the NAT map rule. It can monitor all outbound packet traffic for FTP active or passive start session requests and dynamically create temporary filter rules containing the port number being used by the data channel. This eliminates the security risk FTP normally exposes the firewall to as it no longer needs to open large ranges of high order ports for FTP connections.
This rule will handle all the traffic for the internal LAN:
map dc0 10.0.10.0/29 -> 0/32 proxy port 21 ftp/tcp
This rule handles the FTP traffic from the gateway:
map dc0 0.0.0.0/0 -> 0/32 proxy port 21 ftp/tcp
This rule handles all non-FTP traffic from the internal LAN:
map dc0 10.0.10.0/29 -> 0/32
The FTP map rules go before the NAT rule so that when a packet matches an FTP rule, the FTP proxy creates temporary filter rules to let the FTP session packets pass and undergo NAT. All LAN packets that are not FTP will not match the FTP rules but will undergo NAT if they match the third rule.

IPNAT FTP Filter Rules

Only one filter rule is needed for FTP if the NAT FTP proxy is used.
Without the FTP proxy, the following three rules will be needed:
# Allow out LAN PC client FTP to public Internet
# Active and passive modes
pass out quick on rl0 proto tcp from any to any port = 21 flags S keep state

# Allow out passive mode data channel high order port numbers
pass out quick on rl0 proto tcp from any to any port > 1024 flags S keep state

# Active mode let data channel in from FTP server
pass in quick on rl0 proto tcp from any to any port = 20 flags S keep state