<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>My Pool &#187; Linux</title>
	<atom:link href="http://www.hlouis.com/category/develop/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hlouis.com</link>
	<description>Help, I can&#039;t swimming......</description>
	<lastBuildDate>Tue, 04 May 2010 15:27:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fix IBus Openoffic and Awesome</title>
		<link>http://www.hlouis.com/develop/linux/fix-ibus-openoffic-and-awesome/</link>
		<comments>http://www.hlouis.com/develop/linux/fix-ibus-openoffic-and-awesome/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 06:44:58 +0000</pubDate>
		<dc:creator>Louis</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.hlouis.com/?p=92</guid>
		<description><![CDATA[Add following line to soffice start script
# IBUS was confilict with OOO3 under awesomedon&#8217;t know why, but add the blow  
# line, everything OK then~ cheers
OOO_FORCE_DESKTOP=gnome export OOO_FORCE_DESKTOP 
]]></description>
			<content:encoded><![CDATA[<p>Add following line to soffice start script</p>
<blockquote><p># IBUS was confilict with OOO3 under awesomedon&#8217;t know why, but add the blow  <br />
# line, everything OK then~ cheers</p>
<p>OOO_FORCE_DESKTOP=gnome export OOO_FORCE_DESKTOP </p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.hlouis.com/develop/linux/fix-ibus-openoffic-and-awesome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Iptables: How-to Share your internet connection</title>
		<link>http://www.hlouis.com/develop/linux/iptables-how-to-share-your-internet-connection/</link>
		<comments>http://www.hlouis.com/develop/linux/iptables-how-to-share-your-internet-connection/#comments</comments>
		<pubDate>Tue, 20 Nov 2007 02:49:55 +0000</pubDate>
		<dc:creator>Louis</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.hlouis.com/diary/iptables-how-to-share-your-internet-connection/</guid>
		<description><![CDATA[from  http://www.debuntu.org/iptables-how-to-share-your-internet-connection

   
iptables is a command line tool which allow system administrators to configure Linux packet filtering ruleset.
Using iptables, you are able to tweak packet filtering, Network Address Translation (NAT) and packet mangling which in the end are going to allow you to secure your server, share your Internet connection and log [...]]]></description>
			<content:encoded><![CDATA[<p>from  http://www.debuntu.org/iptables-how-to-share-your-internet-connection<!-- google_ad_section_start --></p>
<p class="ad-auto-inserted" style="margin: 0pt 1em 0.25em 0pt; float: left"><!--adsense: cached--></p>
<p class="adsense"> <script type="text/javascript"><!-- google_alternate_ad_url = "http://www.debuntu.org/altadd/rectangle-300.php"; google_ad_client = "pub-3316878663386307"; google_ad_type = "text_image"; google_ad_channel = "8357962815"; google_ad_width = 336; google_ad_height = 280; google_ad_format = "336x280_as"; google_color_border = "ffffff"; google_color_bg = "FAFCFF"; google_color_link = "0A8FBC"; google_color_url = "008000"; google_color_text = "000000"; //--></script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script></p>
<p><strong><a href="http://netfilter.org/" title="iptables" target="_">iptables</a></strong> is a command line tool which allow system administrators to configure Linux packet filtering ruleset.</p>
<p>Using <strong>iptables</strong>, you are able to tweak <em>packet filtering</em>, <em>Network Address Translation</em> (NAT) and <em>packet mangling</em> which in the end are going to allow you to secure your server, share your Internet connection and log unwanted traffic.</p>
<p><strong>iptables</strong> is not really what we could call an easy to get with tool, but once you know the basis, it won&#8217;t be that scary <img src='http://www.hlouis.com/hlouis_com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>This tutorial will provide a sample script you can use to share your Internet access and will give an overview on how to use <strong>iptables</strong></p>
<h2>1. Introduction</h2>
<p>Most people will be freaked out when you pronounce the name <strong>iptables</strong> because it is not much of an easy to understand software, man page is huge as well as <strong>iptables</strong> capabilities.<br />
To be able to set up a home router, you don&#8217;t actually need to spend nights and nights going through iptables man page, a grasp of the basis is enough to get your firewall up and running.</p>
<p>This tutorial provides a sample script you should be able to use out of the box or at most, changing 2 parameters will be able to get you running.</p>
<h2>2. Iptables</h2>
<p>To be able to understand what the firewall do, there is some basis you need to know. Here I&#8217;m going to go over what make <strong>iptables</strong> handle network packets.</p>
<h3>2.1. Chain Rules</h3>
<p><strong>Iptables</strong> use a set of <em>chain rules</em> to check weather or not a packet should be accepted. By default, there is 3 chains:</p>
<ul>
<li><strong>INPUT</strong>: packet is destinate to the machine running iptables</li>
<li><strong>FORWARD</strong>: packet needs to be forwarded to another machine</li>
<li><strong>OUTPUT</strong>: packet going out of the machine running iptables</li>
</ul>
<p>So when a packet reaches the firewall, the first thing the kernel is going to do is to determine where the packet is going. According to the destination, the kernel will check the packet against the rules of the appropriate chain.</p>
<h3>2.2. Actions (TARGET)</h3>
<p>For each <em>chain</em> we define a list of <em>rules</em> and <em>actions</em> (called <em>targets</em> in iptables&#8217;jargon) to take when a packet match a rule. Main actions are:</p>
<ul>
<li><strong>ACCEPT</strong>: accept the packet <img src='http://www.hlouis.com/hlouis_com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li><strong>REJECT</strong>: discard the packet and inform the source</li>
<li><strong>DROP</strong>: discard the packet but don&#8217;t say anything to the source</li>
</ul>
<p>As soon as a packet has matched a rule, the kernel will apply the action it is said to do and won&#8217;t go further. If the packet did not match any rules, the kernel will use the <span class="tech">default policy</span> defined for that chain.</p>
<p>This beeing said, we can now get into the script.</p>
<p><span id="more-66"></span></p>
<h2>3. Iptables Script</h2>
<p>OK, now that we know the really basis, let see what the script is going to look like.</p>
<p>In this example, I assume that <em>eth0</em> is the interface connected to the Internet, <em>eth1</em> is the one connected to our local network.</p>
<blockquote>
<pre class="file">#!/bin/sh
#
# this script requires iptables package to be
# installed on your machine

# Where to find iptables binary
IPT="/sbin/iptables"

# The network interface you will use
# WAN is the one connected to the internet
# LAN the one connected to your local network
WAN="eth0"
LAN="eth1"
# First we need to clear up any existing firewall rules
# and chain which might have been created
$IPT -F
$IPT -F INPUT
$IPT -F OUTPUT
$IPT -F FORWARD
$IPT -F -t mangle
$IPT -F -t nat
$IPT -X

# Default policies: Drop any incoming packets
# accept the rest.
$IPT -P INPUT DROP
$IPT -P OUTPUT ACCEPT
$IPT -P FORWARD ACCEPT

# To be able to forward traffic from your LAN
# to the Internet, we need to tell the kernel
# to allow ip forwarding
echo 1 &gt; /proc/sys/net/ipv4/ip_forward

# Masquerading will make machines from the LAN
# look like if they were the router
$IPT -t nat -A POSTROUTING -o $WAN -j MASQUERADE

# If you want to allow traffic to specific port to be
# forwarded to a machine from your LAN
# here we forward traffic to an HTTP server to machine 192.168.0.2
#$IPT -t nat -A PREROUTING -i $WAN -p tcp --dport 80 -j DNAT --to 192.168.0.2:80
#$IPT -A FORWARD -i $WAN -p tcp  --dport 80 -m state --state NEW -j ACCEPT
# For a whole range of port, use:
#$IPT -t nat -A PREROUTING -i $WAN -p tcp --dport 1200:1300 -j DNAT --to 192.168.0.2
#$IPT -A FORWARD -i $WAN -p tcp  --dport 1200:1300 -m state --state NEW -j ACCEPT

# Do not allow new or invalid connections to reach your internal network
$IPT -A FORWARD -i $WAN -m state --state NEW,INVALID -j DROP

# Accept any connections from the local machine
$IPT -A INPUT -i lo -j ACCEPT
# plus from your local network
$IPT -A INPUT -i $LAN -j ACCEPT

# Here we define a new chain which is going to handle
# packets we don't want to respond to
# limit the amount of logs to 10/min
$IPT -N Firewall
$IPT -A Firewall -m limit --limit 10/minute -j LOG --log-prefix "Firewall: "
$IPT -A Firewall -j DROP

# log those packets and inform the sender that the packet was rejected
$IPT -N Rejectwall
$IPT -A Rejectwall -m limit --limit 10/minute -j LOG --log-prefix "Rejectwall: "
$IPT -A Rejectwall -j REJECT
# use the following instead if you want to simulate that the host is not reachable
# for fun though
#$IPT -A Rejectwall -j REJECT  --reject-with icmp-host-unreachable

# here we create a chain to deal with unlegitimate packets
# and limit the number of alerts to 10/min
# packets will be drop without informing the sender
$IPT -N Badflags
$IPT -A Badflags -m limit --limit 10/minute -j LOG --log-prefix "Badflags: "
$IPT -A Badflags -j DROP

# A list of well known combination of Bad TCP flags
# we redirect those to the Badflags chain
# which is going to handle them (log and drop)
$IPT -A INPUT -p tcp --tcp-flags ACK,FIN FIN -j Badflags
$IPT -A INPUT -p tcp --tcp-flags ACK,PSH PSH -j Badflags
$IPT -A INPUT -p tcp --tcp-flags ACK,URG URG -j Badflags
$IPT -A INPUT -p tcp --tcp-flags FIN,RST FIN,RST -j Badflags
$IPT -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j Badflags
$IPT -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j Badflags
$IPT -A INPUT -p tcp --tcp-flags ALL ALL -j Badflags
$IPT -A INPUT -p tcp --tcp-flags ALL NONE -j Badflags
$IPT -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j Badflags
$IPT -A INPUT -p tcp --tcp-flags ALL SYN,FIN,PSH,URG -j Badflags
$IPT -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j Badflags

# Accept certain icmp message, drop the others
# and log them through the Firewall chain
# 0 =&gt; echo reply
$IPT -A INPUT -p icmp --icmp-type 0 -j ACCEPT
# 3 =&gt; Destination Unreachable
$IPT -A INPUT -p icmp --icmp-type 3 -j ACCEPT
# 11 =&gt; Time Exceeded
$IPT -A INPUT -p icmp --icmp-type 11 -j ACCEPT
# 8 =&gt; Echo
# avoid ping flood
$IPT -A INPUT -p icmp --icmp-type 8 -m limit --limit 1/second -j ACCEPT
$IPT -A INPUT -p icmp -j Firewall

# Accept ssh connections from the Internet
$IPT -A INPUT -i $WAN -p tcp --dport 22 -j ACCEPT
# or only accept from a certain ip
#$IPT -A INPUT -i $WAN -s 125.124.123.122 -p tcp --dport 22 -j ACCEPT

# Accept related and established connections
$IPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

# Drop netbios from the outside, no log, just drop
$IPT -A INPUT -p udp --sport 137 --dport 137 -j DROP

# Finally, anything which was not allowed yet
# is going to go through our Rejectwall rule
$IPT -A INPUT -j Rejectwall</pre>
</blockquote>
<h3>3.1. Iptables default settings</h3>
<p>First of all, we define where <strong>iptables</strong> binary is located and to make the script easier to attapt to other situation, we define the interface as <em>WAN</em> and <em>LAN</em>.<br />
So, if your machine uses <em>eth1</em> as the interface connected to the Internet and <em>eth0</em> connected to your local network, simply change:</p>
<blockquote>
<p class="dump"> WAN=&#8221;eth0&#8243;<br />
LAN=&#8221;eth1&#8243;</p></blockquote>
<p>to</p>
<blockquote>
<p class="dump"> WAN=&#8221;eth1&#8243;<br />
LAN=&#8221;eth0&#8243;</p></blockquote>
<p>Then we clean up <strong>iptables</strong> by <span class="tech">flushing</span> all the chain and tables:</p>
<blockquote>
<p class="dump">$IPT -F xxx</p>
</blockquote>
<p>and deleting all the <em>optional user-defined chains</em>:</p>
<blockquote>
<p class="dump">$IPT -X</p>
</blockquote>
<p>Then we define the <strong>default policies</strong>:</p>
<blockquote>
<p class="dump">$IPT -P xxx</p>
</blockquote>
<p>Which is to <strong>DROP</strong> any packet which is destinated to the local machine if they were not accepting, <strong>ACCEPT</strong> any packet which is going out of the local machine or going to/coming from our LAN if they were not discarded yet.</p>
<h3>3.2. To and From Local Network</h3>
<p>Because we want to be able to forward traffic, we need to say so to the kernel. This is what is done by setting <span class="tech">/proc/sys/net/ipv4/ip_forward</span> to 1.</p>
<p>Then, we need to tell the kernel to <em>masquerade</em> all <em>outgoing</em> traffic. This is what is achieved by triggering:</p>
<blockquote>
<p class="dump">$IPT -t nat -A POSTROUTING -o $WAN -j MASQUERADE</p>
</blockquote>
<p>Masquerading has the effect of allowing all computer from your internal network to access the internet. These machines will be seen as if there were the router itself.</p>
<p>Now, suppose you want your apache server on machine 192.168.0.2 to be visible from the outside. You need to tell the firewall to send those packets to machine 192.168.0.2 on port 80, this is what is achieved with:</p>
<blockquote>
<p class="dump">$IPT -t nat -A PREROUTING -i $WAN -p tcp &#8211;dport 80 -j DNAT &#8211;to 192.168.0.2:80</p>
</blockquote>
<p>But then, you also need to accept new connection on that specific port because, as you will see later on, we by default forbid <em>NEW</em> and <em>INVALID</em> connections coming from the outside to be forwarded.<br />
So, for that specific service, we will allow <em>NEW</em> connections (<em>RELATED</em> and <em>ESTABLISHED</em> being allowed by default) to be forwarded:</p>
<blockquote>
<p class="dump">$IPT -A FORWARD -i $WAN -p tcp  &#8211;dport 80 -m state &#8211;state NEW -j ACCEPT</p>
</blockquote>
<p>And now, let discard any <em>NEW</em> and <em>INVALID</em> connections:</p>
<blockquote>
<p class="dump">$IPT -A FORWARD -i $WAN -m state &#8211;state NEW,INVALID -j DROP</p>
</blockquote>
<p>To be able to have your local connection to work properly, you need to accept everything on localhost. This is done with:</p>
<blockquote>
<p class="dump"> # Accept any connections from the local machine<br />
$IPT -A INPUT -i lo -j ACCEPT</p></blockquote>
<p class="warning"> We do not need to use the statement <span class="tech">$IPT -A OUTPUT -i lo -j ACCEPT</span> because the default <strong>OUTPUT policy</strong> is set to <strong>ACCEPT</strong><br />
If your default policy is different, you might have to add this statement</p>
<p>Then, because in our example we trust our local network (not a wise thing to do though), we need to allow any incoming connections from our LAN:</p>
<blockquote>
<p class="dump"># plus from your local network<br />
$IPT -A INPUT -i $LAN -j ACCEPT</p></blockquote>
<h3>3.3. Defining custom chains</h3>
<p>In order to get a easier to maintain <strong>iptables</strong> script, it is handy to define some custom chains, also called <em>user-defined chains</em>. This way, you can gather common actions into 1 chain, then, using our target switch (<em>-j</em>) we will be able to send packets that match specific rules to that target.<br />
In order to create a <em>user-defined chain</em>, we need to use:</p>
<blockquote>
<p class="shell">iptables -N chain_name</p>
</blockquote>
<p>and then simply add rules to that chain using the usual:</p>
<blockquote>
<p class="shell">iptables -A chain_name [rules ...] -j target</p>
</blockquote>
<p>Okie, now that this is explained, we are going to create 3 <em>user-defined chains</em> which are going to <span class="system">log</span> packet matching rules to be sent to this specific chain:</p>
<ul>
<li>Firewall: is going to log packets by prepending &#8220;Firewall: &#8221; and DROP them, as you will see, this will only deal with ICMP</li>
<li>Rejectwall: is going to log packets (prepending &#8220;Rejectwall: &#8220;) that were not accepted my any previous rules</li>
<li>Badflags: is going to log packets which TCP flags are not properly set. Some kind of packets are usually used during attack. (prepending &#8220;Badflags: &#8220;)</li>
</ul>
<p>The bit of code that deals with the chain creation and which append rules to it is:</p>
<blockquote>
<p class="dump"> # Here we define a new chain which is going to handle<br />
# packets we don&#8217;t want to respond to<br />
# limit the amount of logs to 10/min<br />
$IPT -N Firewall<br />
$IPT -A Firewall -m limit &#8211;limit 10/minute -j LOG &#8211;log-prefix &#8220;Firewall: &#8221;<br />
$IPT -A Firewall -j DROP</p>
<p># log those packets and inform the sender that the packet was rejected<br />
$IPT -N Rejectwall<br />
$IPT -A Rejectwall -m limit &#8211;limit 10/minute -j LOG &#8211;log-prefix &#8220;Rejectwall: &#8221;<br />
$IPT -A Rejectwall -j REJECT<br />
# use the following instead if you want to simulate that the host is not reachable<br />
# for fun though<br />
#$IPT -A Rejectwall -j REJECT  &#8211;reject-with icmp-host-unreachable</p>
<p># here we create a chain to deal with unlegitimate packets<br />
# and limit the number of alerts to 10/min<br />
# packets will be drop without informing the sender<br />
$IPT -N Badflags<br />
$IPT -A Badflags -m limit &#8211;limit 10/minute -j LOG &#8211;log-prefix &#8220;Badflags: &#8221;<br />
$IPT -A Badflags -j DROP</p></blockquote>
<p>As you can see, there is a new <strong>target</strong> (<em>action</em>), namely <strong>LOG</strong>. <strong>LOG</strong> is a specific target that logs the packet to /var/log/messages usually. <strong>LOG</strong> is a <em>non-terminating target</em>, this means that the packet is going to continue to the next rule after being logged.<br />
by using the <em>&#8211;log-prefix</em> you can specify what is going to be prepended to your log.</p>
<p>So let&#8217;s take the example of chain &#8220;Firewall&#8221;.<br />
First we create the chain: <em>$IPT -N Firewall</em><br />
Then, we ask the kernel to log the packet and to prepend &#8220;Firewall: &#8221; to the log string. But because we don&#8217;t want our logs to be flooded by such logs, we cap the number of logs related to the Firewall chain to 10/minute: <em>$IPT -A Firewall -m limit &#8211;limit 10/minute -j LOG &#8211;log-prefix &#8220;Firewall: &#8220;</em><br />
Finally, after we logged the packet, we are simply going to DROP it: <em>$IPT -A Firewall -j DROP</em></p>
<h3>3.4. Using those rules</h3>
<p>Creating <em>user-defined chain</em> will now make it easier and faster for us to operate specific actions on packets.<br />
Let&#8217;s go through the block of statements related to bad TCP flags:</p>
<blockquote>
<p class="dump"> # A list of well known combination of Bad TCP flags<br />
# we redirect those to the Badflags chain<br />
# which is going to handle them (log and drop)<br />
$IPT -A INPUT -p tcp &#8211;tcp-flags ACK,FIN FIN -j Badflags<br />
$IPT -A INPUT -p tcp &#8211;tcp-flags ACK,PSH PSH -j Badflags<br />
$IPT -A INPUT -p tcp &#8211;tcp-flags ACK,URG URG -j Badflags<br />
$IPT -A INPUT -p tcp &#8211;tcp-flags FIN,RST FIN,RST -j Badflags<br />
$IPT -A INPUT -p tcp &#8211;tcp-flags SYN,FIN SYN,FIN -j Badflags<br />
$IPT -A INPUT -p tcp &#8211;tcp-flags SYN,RST SYN,RST -j Badflags<br />
$IPT -A INPUT -p tcp &#8211;tcp-flags ALL ALL -j Badflags<br />
$IPT -A INPUT -p tcp &#8211;tcp-flags ALL NONE -j Badflags<br />
$IPT -A INPUT -p tcp &#8211;tcp-flags ALL FIN,PSH,URG -j Badflags<br />
$IPT -A INPUT -p tcp &#8211;tcp-flags ALL SYN,FIN,PSH,URG -j Badflags<br />
$IPT -A INPUT -p tcp &#8211;tcp-flags ALL SYN,RST,ACK,FIN,URG -j Badflags</p></blockquote>
<p>As you can see, for any of the packet matching a rule, we simply have to send the packet to the &#8220;<em>Badflags</em>&#8221; chain. If we were not using <em>user-defined chains</em>, the first statement would look like:</p>
<blockquote>
<p class="dump"> $IPT -A INPUT -p tcp &#8211;tcp-flags ACK,FIN FIN -m limit &#8211;limit 10/minute -j LOG &#8211;log-prefix &#8220;Badflags: &#8221;<br />
$IPT -A INPUT -p tcp &#8211;tcp-flags ACK,FIN FIN -j DROP</p></blockquote>
<p>So this would be twice as much work :s. Now, imagine you want to change the target from DROP to REJECT, you simply have to edit 1 line instead of 11 <img src='http://www.hlouis.com/hlouis_com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p class="tip">Those badflags rules are well known combinations of illegitimated TCP flags settings. Normal application should not use those, this is why we can DROP those packets safely.</p>
<p>Now, we are going to allow only a small set of <span class="tech">ICMP</span> packets. In our example, we want our firewall to be able to receive information such as <em>Timeout</em> (type 11), <em>Host unreachable</em> (type 3) and we want it to reply to pings (type 8 ) and get replies to ping initiated from our firewall (type 0).<br />
In order to do this, we ACCEPT any <em>ICMP</em> packets which contains one of the following code type and then pass all other <em>ICMP</em> packets code to our <strong>Firewall</strong> chain.</p>
<blockquote>
<p class="dump"> # Accept certain icmp message, drop the others<br />
# and log them through the Firewall chain<br />
# 0 =&gt; echo reply<br />
$IPT -A INPUT -p icmp &#8211;icmp-type 0 -j ACCEPT<br />
# 3 =&gt; Destination Unreachable<br />
$IPT -A INPUT -p icmp &#8211;icmp-type 3 -j ACCEPT<br />
# 11 =&gt; Time Exceeded<br />
$IPT -A INPUT -p icmp &#8211;icmp-type 11 -j ACCEPT<br />
# 8 =&gt; Echo<br />
# avoid ping flood<br />
$IPT -A INPUT -p icmp &#8211;icmp-type 8 -m limit &#8211;limit 1/second -j ACCEPT<br />
$IPT -A INPUT -p icmp -j Firewall</p></blockquote>
<p class="tip">Note the <span class="tech">-m limit &#8211;limit 1/second</span>, by doing such, our firewall is going to reply to only 1 ping per second, any other ping will be logged (up to 10/min and then DROPped) through the <em>Firewall</em> chain</p>
<h3>3.5. Traffic from the Internet</h3>
<p>After we have dealt with not well formed packets and icmp packets, we should apply some global rules to streams coming from the outside (remember that our default policy for OUTPUT packets is ACCEPT, so we don&#8217;t have to allow those).</p>
<p>The basic idea here is to only allow streams that are related to a previous connection (useful for FTP for instance) or already established.<br />
But, we are going to make one exception for <span class="tech">SSH</span> because we want to be able to connect to our box from the outside.</p>
<p>We achieve this by accepting any ssh packets from the outside and then only connections in state RELATED or ESTABLISHED</p>
<blockquote>
<p class="dump"> # Accept ssh connections from the Internet<br />
$IPT -A INPUT -i $WAN -p tcp &#8211;dport 22 -j ACCEPT<br />
# or only accept from a certain ip<br />
#$IPT -A INPUT -i $WAN -s 125.124.123.122 -p tcp &#8211;dport 22 -j ACCEPT</p>
<p># Accept related and established connections<br />
$IPT -A INPUT -m state &#8211;state RELATED,ESTABLISHED -j ACCEPT</p></blockquote>
<p>Then we are going to DROP silently netbios scan from the outside:</p>
<blockquote>
<p class="dump"> # Drop netbios from the outside, no log, just drop<br />
$IPT -A INPUT -p udp &#8211;sport 137 &#8211;dport 137 -j DROP</p></blockquote>
<p>And finally, REJECT any other packet through our user-defined chain <em>Rejectwall</em>:</p>
<blockquote>
<p class="dump"> $IPT -A INPUT -j Rejectwall</p>
</blockquote>
<h2>4. Using iptables&#8217;script</h2>
<h3>4.1. From the command line</h3>
<p>One way to apply the rules we define, is simply to run the script from the command line like:</p>
<p class="shell">sudo sh /path/to/firewall-script.sh</p>
<p>but this has the bad effect of not being restore on reboot :s, but still, this will be of great help while tweaking up your firewall.</p>
<h3>4.2. Using /etc/rc.local</h3>
<p><strong>/etc/rc.local</strong> is a custom file where you can add scripts to be executed at the end of each multiuser runlevel.</p>
<p>By default, this file only contain <em>exit 0</em>.<br />
In order to have your iptables firewall script executed on reboot, simply add the path to your firewall script before <em>exit 0</em>.</p>
<p>Copy your firewall script file to /etc/firewall-script.sh for instance. Then make it executable:</p>
<blockquote>
<p class="shell">sudo chmod 700 /etc/firewall-script.sh</p>
</blockquote>
<p>Then edit /etc/rc.local and add <em>/etc/firewall-script.sh</em> before exit 0</p>
<p>Next time you are going to reboot, this script is going to be executed and therefore, your firewall set up restored.</p>
<h3>4.3. Using /etc/network/if-up.d/ directory</h3>
<p>This one is a bit more tricky.<br />
Once you are done with setting up your firewall script, you will save it to the <em>iptables format</em> by trigerring:</p>
<p class="shell"> $sudo sh /path/to/firewall/script.sh<br />
$sudo iptables-save &gt; /etc/firewall-iptables.conf</p>
<p>Now, open and edit <em>/etc/network/if-up.d/iptables</em> and make it look like:</p>
<blockquote>
<pre class="file">#!/bin/sh
iptables-restore &lt; /etc/firewall-iptables.conf</pre>
</blockquote>
<p>Then make it executable:</p>
<blockquote>
<p class="shell">sudo chmod +x /etc/network/if-up.d/iptables</p>
</blockquote>
<p>Finally, we need a way to set up <em>/proc/sys/net/ipv4/ip_forward</em> to 1. This can be achieved through <span class="tech">/etc/sysctl.conf</span>.<br />
Simply add the following entry if not already there:</p>
<blockquote>
<p class="dump">net.ipv4.ip_forward=1</p>
</blockquote>
<p>which will set /proc/sys/net/ipv4/ip_forward to 1 next time you reboot.</p>
<p class="tip">We could have also used /etc/firewall-script.sh instead of the <em>iptables-restore</em> trick, but this way, you can see another way to do it</p>
<p>Reboot, your firewall should be up again <img src='http://www.hlouis.com/hlouis_com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>4.4. Once upon a time</h3>
<p>Debian used to have this great <span class="tech">/etc/init.d/iptables</span> init script which allowed you to restore iptables settings on boot up, stop your firewall &#8230;<br />
This script is now gone&#8230; so we have got to do it by ourself now <img src='http://www.hlouis.com/hlouis_com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<h3>4.5. Rescue script</h3>
<p>A handy script to have around is a script that can erase all chains and rules in case you are getting lost with your firewall breakages. The following script will clear up all rules and reset all chain so your firewall will be inactive. I suggest you copy it and keep it somewhere close to you in case of emergency.</p>
<blockquote><p>#!/bin/bash<br />
IPT=&#8217;/sbin/iptables&#8217;</p>
<p>for a in `cat /proc/net/ip_tables_names`; do<br />
${IPT} -F -t $a<br />
${IPT} -X -t $a</p>
<p>if [ $a = nat ]; then<br />
${IPT} -t nat -P PREROUTING ACCEPT<br />
${IPT} -t nat -P POSTROUTING ACCEPT<br />
${IPT} -t nat -P OUTPUT ACCEPT<br />
elif [ $a = mangle ]; then<br />
${IPT} -t mangle -P PREROUTING ACCEPT<br />
${IPT} -t mangle -P INPUT ACCEPT<br />
${IPT} -t mangle -P FORWARD ACCEPT<br />
${IPT} -t mangle -P OUTPUT ACCEPT<br />
${IPT} -t mangle -P POSTROUTING ACCEPT<br />
elif [ $a = filter ]; then<br />
${IPT} -t filter -P INPUT ACCEPT<br />
${IPT} -t filter -P FORWARD ACCEPT<br />
${IPT} -t filter -P OUTPUT ACCEPT<br />
fi</p></blockquote>
<pre class="file">done</pre>
<h2>5. Conclusion</h2>
<p>This tutorial covered <strong>iptables</strong> in order to set up a linux firewall which will share your internet connection amongst computer from your local network.<br />
By explaining <strong>iptables</strong> basis, you should now be able to improve your script so you can allow or disallow specific types of traffic.</p>
<p>This is not the most secure set up though. Best practice would be to set up a policy which disallow all traffic by default and then only allow the traffic you believe that should be permitted.</p>
<p>Finally we went through different ways of recovering iptables setting on reboot.</p>
<p>Hope this helps and will give you enough basis to customize your firewall.</p>
<p class="dump">&nbsp;</p>
<blockquote>
<p class="dump"><a href="http://www.hlouis.com/hlouis_com/wp-content/uploads/2007/11/firewall-simple.txt" title="firewall-simple.txt">firewall-simple.txt<br />
</a><a href="http://www.hlouis.com/hlouis_com/wp-content/uploads/2007/11/firewall-stop.txt" title="firewall-stop.txt">firewall-stop.txt</a><a href="http://www.hlouis.com/hlouis_com/wp-content/uploads/2007/11/firewall-simple.txt" title="firewall-simple.txt"><br />
</a></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.hlouis.com/develop/linux/iptables-how-to-share-your-internet-connection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How-to get your removable device mounted under an explicit and persistent name</title>
		<link>http://www.hlouis.com/develop/linux/give-removable-device-a-name/</link>
		<comments>http://www.hlouis.com/develop/linux/give-removable-device-a-name/#comments</comments>
		<pubDate>Tue, 20 Nov 2007 02:29:20 +0000</pubDate>
		<dc:creator>Louis</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.hlouis.com/develop/linux/give-removable-device-a-name/</guid>
		<description><![CDATA[from  http://www.debuntu.org/device-partition-labeling
You might have wondered how comes that your mp3 player is automatically mounted under a nice name like JUKEBOX for instance, while you usb stick simply get a name like USB_BAR and USB_BAR-1&#8230; for its partitions.
This is actually due to hal automatically mounting the device.
This tutorial will show you how to give a label [...]]]></description>
			<content:encoded><![CDATA[<p>from  <a href="http://www.debuntu.org/device-partition-labeling">http://www.debuntu.org/device-partition-labeling</a></p>
<p>You might have wondered how comes that your mp3 player is automatically mounted under a nice name like <em>JUKEBOX</em> for instance, while you usb stick simply get a name like <em>USB_BAR</em> and <em>USB_BAR-1</em>&#8230; for its partitions.<br />
This is actually due to <strong>hal</strong> automatically mounting the device.<br />
This tutorial will show you how to give a label to your partitions in order to have your removable devices mounted under an explicit location such as: <em>/media/red-usb-disk</em> or <em>/media/my-big-fat-partition</em>.</p>
<p>When automatically mounting a device, it happens that <strong>hal</strong> already know about this device, in which case, the device is going to be mounted under, let say for an Ipod, /media/Ipod. But if you have an external hard-drive that you connect through usb, chances are that your external hard-drive partitions are mounted under <em>/media/usbdisk</em>, <em>/media/usbdisk-1</em> and so on.<br />
And actually, partition one might be mounted under usbdisk-1 on day and usbdisk the day after :s.<br />
Imagine you stock all you music on your external hardrive. Today, you hardrive get mounted under /media/usbdisk and you create a playlist. Tomorrow, when you plug you hardrive, your music partition might get mounted under /media/usbdisk-1, you start your music player, this one kept your last playlist in memory, but you simply can&#8217;t replay it because the files have moved from /media/usbdisk to /media/usbdisk-1 <img src='http://www.hlouis.com/hlouis_com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> .<br />
This is where labeling a partition will become handy.</p>
<p><span id="more-65"></span></p>
<p><a title="mainmenu" name="mainmenu"></a> Here is a menu that will let you jump directly to a specific filesystem type:</p>
<ul>
<li><a href="http://www.debuntu.org/device-partition-labeling#ext">ext2 and ext3</a></li>
<li><a href="http://www.debuntu.org/device-partition-labeling#reiserfs">reiserfs</a></li>
<li><a href="http://www.debuntu.org/device-partition-labeling#vfat">vfat</a></li>
<li><a href="http://www.debuntu.org/device-partition-labeling#xfs">XFS</a>: not tested, need your feedback</li>
<li><a href="http://www.debuntu.org/device-partition-labeling#jfs">JFS</a>: not tested, need your feedback</li>
</ul>
<p>Because linux comes with a whole range of file systems, we are going to need different tools depending on which filesystem you are using.<br />
From now on, I will suppose you know which file system your device is formated to. If you don&#8217;t know yet, simply plug you device in order to get it mounted, the run:</p>
<p class="shell">$ df -T</p>
<p>This will output something like:</p>
<p class="dump"> &#8230;..<br />
&#8230;..<br />
/dev/scd0  iso9660     3011040   3011040         0 100% /media/cdrom0<br />
/dev/sdb1     vfat      244480     20756    223724   9% /media/USBDRIVE</p>
<p>You can find the file system type on the second column: here iso9660 for the cdrom and vfat for the usb disk. The device name is found in the first column: here /dev/scd0 and /dev/sdb1</p>
<p>From now on, we are going to work on device /dev/sdaX, you will have to adjust this in accordance with the device you want to rename. Let&#8217;s get into it now <img src='http://www.hlouis.com/hlouis_com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<h2><a title="ext" name="ext"></a> Ext2 and ext3 file systems</h2>
<p><a href="http://www.debuntu.org/device-partition-labeling#mainmenu">back to file systems menu</a></p>
<p>In order to change the label of an ext2 or ext3 partition, you will need to use: <strong>e2fsprogs</strong> program utilities. If it is not yet install on your computer, run the following command to install it:</p>
<p class="shell">$ sudo apt-get install e2fsprogs</p>
<h3>Retrieving the existing label</h3>
<p>In order to retrieve the existing label of your partition, simply run:</p>
<p class="shell">$ sudo e2label /dev/sdaX<br />
my label</p>
<h3>Setting a new label</h3>
<p>To set up a new label, you simply have to append the label name at the end of the command line, so it will look like:</p>
<p class="shell">$ sudo e2label /dev/sdaX &#8220;my new label&#8221;</p>
<p class="important">ext2/3 label has to be at most 16 characters long, if longer, label will be truncated</p>
<p>In order to confirm that your changes where properly applied, you can retrieve the partition&#8217;s label with:</p>
<p class="shell">$ sudo e2label /dev/sdaX<br />
my new label</p>
<p>The new label should be output on the next line.</p>
<h3>Deleting an existing label</h3>
<p>Label can be deleted by supplying an empty label to <strong>e2label</strong> with this command line:</p>
<p class="shell">$ sudo e2label /dev/sdaX &#8220;&#8221;</p>
<h2><a title="reiserfs" name="reiserfs"></a> Reiserfs file system</h2>
<p><a href="http://www.debuntu.org/device-partition-labeling#mainmenu">back to file systems menu</a></p>
<p>First of all, you need to have <strong>reiserfsprogs</strong> package installed. If it not yet present on your machine, please run:</p>
<p class="shell">$ sudo apt-get install reiserfsprogs</p>
<p class="important">While working on a <strong>reiserfs</strong> partition, the partition needs to be unmounted.</p>
<p>Now that you made sure that your partition is <span class="tech">unmounted</span>, let see how it works.</p>
<h3>Retrieving the existing label</h3>
<p>To retrieve the existing label, run:</p>
<p class="shell">$ sudo reiserfstune /dev/sdaX | grep LABEL<br />
&#8230;<br />
LABEL:</p>
<p>The label is going to be apended to &#8220;LABEL: &#8220;, if there is no label yet, only &#8220;LABEL: &#8221; will appear.</p>
<h3>Setting a new label</h3>
<p>To set up a new label, you will need to use the <em>-l</em> switch like:</p>
<p class="shell">$ sudo reiserfstune /dev/sdaX -l &#8220;my new label&#8221;</p>
<p>Check for the &#8220;LABEL: &#8221; entry in the output, this one should now print:</p>
<p class="dump">LABEL: my new label</p>
<p class="important">Reiserfs label has to be at most 16 characters long, if longer, label will be truncated</p>
<h3>Removing an existing label</h3>
<p>To do so, simply supply an empty label with this command line:</p>
<p class="shell">$ sudo reiserfstune /dev/sdaX -l &#8220;&#8221;</p>
<h2><a title="vfat" name="vfat"></a> VFAT file system</h2>
<p><a href="http://www.debuntu.org/device-partition-labeling#mainmenu">back to file systems menu</a></p>
<p>This one is a bit more tricky as you can&#8217;t simply use the command line, but you will need to edit a file in order to let the tool know the name of the device.</p>
<p>The package we are going to use here is <em>mtools</em>. If the package is not installed on your machine, please run:</p>
<p class="shell">$ sudo apt-get install mtools</p>
<h3>Informing mtools about your device</h3>
<p><strong>mtools</strong> needs to be told an &#8220;windows like&#8221; device name (something like G:) to match a linux device name. To do so, create and edit file <span class="tech">~/.mtoolsrc</span> and add:</p>
<pre class="file">drive i: file="/dev/sdaX"</pre>
<p>Where <em>i:</em> is the &#8220;windows name&#8221; and <em>/dev/sdaX</em> is the linux file system associated to it.</p>
<h3>Retrieving the existing label</h3>
<p>Now, you can use <strong>mlabel</strong>, provided by <strong>mtools</strong> package to retrieve the existing label. To do so, trigger the folowin command:</p>
<p class="shell">$ mlabel -s i:</p>
<p>Depending if the device already had a label or not, <strong>mlabel</strong> will output either:</p>
<p class="dump">Volume has no label</p>
<p>or</p>
<p class="dump">Volume label is MY LABEL</p>
<h3>Setting a new label</h3>
<p>Setting a new label is done via the following command line:</p>
<p class="shell">$ mlabel i:&#8221;my new label&#8221;</p>
<h3>Deleting an existing label</h3>
<p>Deleting an existing label can be done with:</p>
<p class="shell">$ mlabel -c i:</p>
<p>Doing so, you won&#8217;t be prompt and the label will be removed.</p>
<h2><a title="xfs" name="xfs"></a> XFS file system</h2>
<p><a href="http://www.debuntu.org/device-partition-labeling#mainmenu">back to file systems menu</a></p>
<p>The tool used here is <strong>xfs_admin</strong> provided by <strong>xfsprogs</strong> package, so in the first place you need to have it installed:</p>
<p class="shell">$ sudo apt-get install xfsprogs</p>
<h3>Retrieving an existing label</h3>
<p>To retrieve an existing label, run:</p>
<p class="shell">$ sudo xfs_admin -l /dev/sdaX</p>
<h3>Setting a new label</h3>
<p>A new label can be set with this command line:</p>
<p class="shell">$ sudo xfs_admin -L &#8220;my new label&#8221; /dev/sdaX</p>
<p class="important">XFS file system can only hold a label of at most 12 characters, if the label supplied is longer, the label will be truncated and a warning will be printed.</p>
<h3>Deleting an existing label</h3>
<p>To delete a label, simply supplied an empty label with this command:</p>
<p class="shell">$ sudo xfs_admin -L &#8220;&#8221; /dev/sdaX</p>
<h2><a title="jfs" name="jfs"></a> JFS file system</h2>
<p><a href="http://www.debuntu.org/device-partition-labeling#mainmenu">back to file systems menu</a></p>
<p>Here, we are going to use <strong>jfs_tune</strong> provided by the <strong>jfsutils</strong> package. Install it with:</p>
<p class="shell">$ sudo apt-get install jfsutils</p>
<h2>Retrieving an existing label</h2>
<p>An existing label can be retrieve with:</p>
<p class="shell">$ sudo jfs_tune -l /dev/sdaX | grep label<br />
Volume label:           &#8216;mylabel&#8217;</p>
<h3>Setting a new label</h3>
<p>A new label can be set with the following command line:</p>
<p class="shell">$ sudo jfs_tune -L &#8220;my new label&#8221; /dev/sdaX</p>
<p class="important">JFS file system can only hold a label of at most 16 characters, if the label supplied is longer, the label will be truncated and a warning will be printed.</p>
<h3>Deleting a label</h3>
<p>A label should be deletable using the following command:</p>
<p class="shell">$ sudo jfs_tune -L &#8220;&#8221; /dev/sdaX</p>
<h2>Conclusion</h2>
<p>By using <em>labels</em>, you will be able to have your removable device mounted under persistent names as well as more user friendly names.<br />
For instance, having to usb stick plugged in, it will be easier for you to manipulate datas on the right device, if one is mounted under /media/blue-usbstick and the other one under /media/red-usbstick instead or /dev/disk1 and /dev/disk2 (mainly when those names can be swapped depending which device you plugged in first).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hlouis.com/develop/linux/give-removable-device-a-name/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How-To: Find files on your computer with find</title>
		<link>http://www.hlouis.com/develop/linux/find-files-on-your-computer-with-find/</link>
		<comments>http://www.hlouis.com/develop/linux/find-files-on-your-computer-with-find/#comments</comments>
		<pubDate>Tue, 20 Nov 2007 02:09:49 +0000</pubDate>
		<dc:creator>Louis</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.hlouis.com/develop/linux/find-files-on-your-computer-with-find/</guid>
		<description><![CDATA[from Debian/Ubuntu Tips &#38; Tricks


   
A standard Linux system has an incredible amount of files installed. Looking for a file location can be a painful task to do though a file browser.
Fortunately, there is a nifty command line available by default on any Linux distribution: find.
find can virtually find anything on your computer [...]]]></description>
			<content:encoded><![CDATA[<p>from <a href="http://www.debuntu.org/" title="Home">Debian/Ubuntu Tips &amp; Tricks</a></p>
<p><!-- google_ad_section_start --></p>
<p class="ad-auto-inserted" style="margin: 0pt 1em 0.25em 0pt; float: left"><!--adsense: cached--></p>
<p class="adsense"> <script type="text/javascript"><!-- google_alternate_ad_url = "http://www.debuntu.org/altadd/rectangle-300.php"; google_ad_client = "pub-3316878663386307"; google_ad_type = "text_image"; google_ad_channel = "8357962815"; google_ad_width = 336; google_ad_height = 280; google_ad_format = "336x280_as"; google_color_border = "ffffff"; google_color_bg = "FAFCFF"; google_color_link = "0A8FBC"; google_color_url = "008000"; google_color_text = "000000"; //--></script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script></p>
<p>A standard Linux system has an incredible amount of files installed. Looking for a file location can be a painful task to do though a file browser.</p>
<p>Fortunately, there is a nifty command line available by default on any Linux distribution: <strong>find</strong>.</p>
<p><strong>find</strong> can virtually find anything on your computer and comes with a lot of options. This tutorial will introduce a basic use of it and show how you can search your filesystem for file names matching a name pattern.</p>
<p>On Debian based distros, <strong>find</strong> is part of the package <strong>findutils</strong>. <strong>find</strong> allow one to search for files on a filesystem based on different condition, creation date, modified date, file size, file type, permissions, name &#8230;.</p>
<p>In this tutorial, I will be focused on finding files/directories based on their name, in order to explain in more depth the syntax of find, I will also show how you can narrow down your search by adding condition on size and file modification time.</p>
<p>This will suit most searches, if you need more details, I would recommend looking at the find&#8217;s manpage.</p>
<h2>1. Find basis</h2>
<p>The default syntax of <strong>find</strong> is as such:</p>
<blockquote><p> find  [path] [expression]</p></blockquote>
<p>where <em>path</em> is the path used as root for searching pattern and <em>expression</em> the expression we want the file to match.</p>
<h2>2. Finding a file based on filename</h2>
<p>Let say for instance you want to find all .avi files in users home directories. Search files can be found with the following command:</p>
<p class="shell"># find /home -name &#8216;*.avi&#8217;</p>
<p> If you want to search for *.mpg and *.avi files, you will use the following:</p>
<p class="shell">find /home -name &#8216;*.mpg&#8217; -o -name &#8216;*.avi&#8217;</p>
<p>Case insensitive searches can be achieved by using the -iname switch:</p>
<p class="shell">find /home -iname &#8216;*.mpg&#8217; -o -iname &#8216;*.avi&#8217;</p>
<h2>3. Adding some more criterias</h2>
<p>Those kind of searches might returns far too many results, making it hard to find waht you were looking for in the first place.</p>
<p>Fortunately, you can narrow down the search by adding criteria such as the file size and the file modification date.</p>
<p>Let&#8217;search for .avi files bigger than 700M. This can be done with:</p>
<p class="shell">find /home/ -name &#8216;*.avi&#8217; -a -size +700M</p>
<p>Now, let&#8217;s find the same subset of files that were modified less than 15 days ago:</p>
<p class="shell">find /home/ -name &#8216;*.avi&#8217; -a -size +700M -mtime -15</p>
<h2>4. Adding some actions</h2>
<p>Grand, we can now find files based on a subset of criteria. What would be even better is to apply some actions on those files. Action can be done with the use of <em>-exec</em> switch.<br />
We can now find .avi file that are newer that 15 days, in this example, we are going to move those file to another location: /my/new/movies . I consider that this directory already exist on your system.<br />
Moving .avi files bigger than 700M and younger than 15 days to /my/new/movies can be done with:</p>
<p class="shell">find /home/ -name &#8216;*.avi&#8217; -a -size +700M -mtime -15 -exec mv &#8216;{}&#8217; /my/new/movies/ \;</p>
<p>Mind the use of <strong>&#8216;{}&#8217;</strong> and <strong> \;</strong> (there is a space before \;).<br />
<strong>&#8216;{}&#8217;</strong> matches the file that was found, while <strong> \;</strong> terminate the exec statement.</p>
<h2>5. Conclusion</h2>
<p><strong>find</strong> is a powerful tool with an extensive set of statement. This article only covered a small subset of available features. For more information on the find command I recommend checking out its man page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hlouis.com/develop/linux/find-files-on-your-computer-with-find/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mounting ftp host to local directory on top of FUSE</title>
		<link>http://www.hlouis.com/develop/linux/mounting-ftp-host-to-local-directory-on-top-of-fuse/</link>
		<comments>http://www.hlouis.com/develop/linux/mounting-ftp-host-to-local-directory-on-top-of-fuse/#comments</comments>
		<pubDate>Mon, 19 Nov 2007 05:29:55 +0000</pubDate>
		<dc:creator>Louis</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.hlouis.com/diary/mounting-ftp-host-to-local-directory-on-top-of-fuse-1-votesnovember-17th-2007-mysurface-posted-in-umount-curlftpfs-mount-sudo-admin-hits-813-i-have-wrote-a-post-regarding/</guid>
		<description><![CDATA[From Linux by Examples
    
I have wrote a post regarding on how to access ftp host using curl. And this time, let us look at how to mount the ftp host to a local directory on top of FUSE.
FUSE (Filesystem in userland) is a userland build on top of virtual filesystem, it [...]]]></description>
			<content:encoded><![CDATA[<p>From <a href="http://linux.byexamples.com/archives/344/mounting-ftp-host-to-local-directory-on-top-of-fuse/#more-344">Linux by Examples</a></p>
<p class="vote-container"> <script type="text/javascript"><!-- google_ad_client = "pub-6971492116812805"; google_ad_width = 336; google_ad_height = 280; google_ad_format = "336x280_as"; google_ad_type = "text"; //2007-11-01: linux top post google_ad_channel = "5689853487"; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "FF6600"; google_color_text = "000000"; google_color_url = "008000"; //--> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script></p>
<p><!-- google_ad_section_start -->I have wrote a post regarding on <a href="http://linux.byexamples.com/archives/320/using-curl-to-access-ftp-server/">how to access ftp host using curl</a>. And this time, let us look at how to mount the ftp host to a local directory on top of FUSE.</p>
<p><a href="http://fuse.sourceforge.net/">FUSE</a> (Filesystem in userland) is a userland build on top of virtual filesystem, it allows you to implement functional filesystem in userspace application. Robson Braga Araujo wrote an app based on fuse and curl that allows you to mount a ftp host to a local directory, <a href="http://curlftpfs.sourceforge.net/">curlftpfs</a>.</p>
<p><strong>What is the benefit of mounting ftp host to a local directory?</strong><br />
The most obvious benefit is easing file management in ftp host. After mounting ftp host to a local dir, you can simply copy, move and delete files using command such as cp, mv, rm. You can easily transfer files from your localhost to ftp host and vice versa.</p>
<p><span id="more-344"></span></p>
<p>To mount ftp host to your local directory, first you need to create a local directory, I created a folder ‘myftp’ and mounting it like this</p>
<pre><code>sudo curlftpfs -o allow_other ftp://myusername:mypassword@ftp.mydomain.com myftp</code></pre>
<p>As simple as that, you are now able to access your ftp host locally.</p>
<p><strong>How to unmount it?</strong><br />
Unmount works as usual.</p>
<pre><code>sudo umount myftp</code></pre>
<p><strong>The command line is lengthy for me, can I auto mount my ftp host by putting it to /etc/fstab ?</strong><br />
Yes, curlftpfs support that.<br />
Inject this line to <em>/etc/fstab</em></p>
<pre><code>curlftpfs#myusername:mypassword@ftp.mydomain.com /mnt/myftp fuse allow_other,rw,user,noauto 0 0</code></pre>
<p>With <em>noauto</em> option, this mount point will not be auto mount when your system restart, you need mount it manually. But this time, you do not need to type the long command line, you now can do this:</p>
<pre><code>sudo mount /mnt/myftp</code></pre>
<p>You may observed that I use <strong>allow_other</strong> in the option, so that I can access /mnt/myftp without need to change myself to root.</p>
<p><strong>Security Issues</strong><br />
Try to run the command line below:</p>
<pre><code>ps aux | grep curlftpfs</code></pre>
<p>OMG! my username and password of my ftp host is visible. I am very sensitive about this, I don’t want it to be so visible, what should I do?</p>
<p>You can create .netrc under root directory and modified the mount line in /etc/fstab.</p>
<p>1. Create /root/.netrc and paste these lines in it.</p>
<pre><code>machine ftp.byexamples.com
login myusername
password mypassword</code></pre>
<p>2. Modified the user mode of the file</p>
<pre><code>sudo chmod o-rw /root/.netrc</code></pre>
<p>3. Modified /etc/fstab</p>
<pre><code>curlftpfs#ftp.mydomain.com /mnt/myftp fuse allow_other,rw,user,noauto 0 0</code></pre>
<p>Although your /root/.netrc is in plain text, but you will need to gain root privilege in order to access the file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hlouis.com/develop/linux/mounting-ftp-host-to-local-directory-on-top-of-fuse/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>how to ssh without password</title>
		<link>http://www.hlouis.com/develop/linux/how-to-ssh-without-password/</link>
		<comments>http://www.hlouis.com/develop/linux/how-to-ssh-without-password/#comments</comments>
		<pubDate>Tue, 30 Oct 2007 08:01:31 +0000</pubDate>
		<dc:creator>Louis</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.hlouis.com/develop/how-to-ssh-without-password/</guid>
		<description><![CDATA[from Linux by Examples by mysurface
Search though google, there are a tons of tutorial for accessing a remote site through ssh without a password. I found some tutorial gives too much details. Sometimes, detail’s explanation may confuse the beginners. I just want to make things done, I don’t want to know too much about the [...]]]></description>
			<content:encoded><![CDATA[<p>from Linux by Examples by mysurface</p>
<p>Search though google, there are a tons of tutorial for accessing a remote site through ssh without a password. I found some tutorial gives too much details. Sometimes, detail’s explanation may confuse the beginners. I just want to make things done, I don’t want to know too much about the public key, private key and network authentication’s stuff. Therefore, I am here to provide the clean steps without further explanation .</p>
<p>Let say you want to access to a machine with IP 10.0.0.4, and make sure you have command ssh, ssh-keygen, ssh-copy-id.</p>
<p>First, generate the ‘key’, the key will be used to open the remote machine’s door.</p>
<blockquote><p>ssh-keygen</p></blockquote>
<p>You will see something like that</p>
<p>Enter file in which to save the key (/home/myname/.ssh/id_rsa):</p>
<p>Whatever it appears just press enter until it ends, press enter for passphase as well.</p>
<p>Okay, the ‘key’ will be generated, something looks like ~/.ssh/id_rsa.pub</p>
<p>Copy over the ‘key’ to remote machine, and enter your password</p>
<blockquote><p>ssh-copy-id -i ~/.ssh/id_rsa.pub mysurface@10.0.0.4</p></blockquote>
<p>Done. Now you can ssh 10.0.0.4 with username mysurface without password.</p>
<blockquote><p>ssh mysurface@10.0.0.4</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.hlouis.com/develop/linux/how-to-ssh-without-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clock skew detected&#8230;.</title>
		<link>http://www.hlouis.com/develop/clock-skew-detected/</link>
		<comments>http://www.hlouis.com/develop/clock-skew-detected/#comments</comments>
		<pubDate>Wed, 27 Dec 2006 03:43:08 +0000</pubDate>
		<dc:creator>Louis</dc:creator>
				<category><![CDATA[Develop]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.guidemarvin.com/mypool/index.php/develop/clock-skew-detected/</guid>
		<description><![CDATA[When build the libserial on a newly installed Linux server, Make tell me the Clock skew detected. Your build may be incomplete. 
`make&#8217; uses the last modification time on the files to
figure out what to build.  For example, if the modification
time of a.c is later than the modification time of a.out,
then a.c needs to [...]]]></description>
			<content:encoded><![CDATA[<p>When build the libserial on a newly installed Linux server, Make tell me the Clock skew detected. Your build may be incomplete. </p>
<blockquote><p>`make&#8217; uses the last modification time on the files to<br />
figure out what to build.  For example, if the modification<br />
time of a.c is later than the modification time of a.out,<br />
then a.c needs to me recomplied to create a new a.out.</p>
<p>Sometimes the last modified time on the files is wrong:<br />
because it is greater than the time of day clock.  `make&#8217;<br />
then issues the above message.</p>
<p>Given a standard make system, the quickest fix is:</p>
<p>   cd directory<br />
   # Remove output files<br />
   make clean<br />
   # Put timestamps on all files equal to current time<br />
   find . -exec touch {} \;<br />
   # Rebuild all output files<br />
   make</p>
<p>You usually see these sort of problems in programming<br />
enviroments that use NFS to share files but don&#8217;t sync<br />
clocks using NTP.</p>
<p>Similarly, if you wind the clock back you will see these<br />
messages.  For that reason, when you wind back the clock<br />
a moderate amount most UNIXen slow the clock ticks rather<br />
than turn back time.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.hlouis.com/develop/clock-skew-detected/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
