TCP/IP Port Redirection (SAMBA example)
Imagine you want to map a directory residing on your
Linux/UNIX server (or remote Windows machine) to local drive (e.g. L:\) on your Windows desktop.
Netbios protocol used by Microsoft and SAMBA to access and map remote filesystems, uses port 139.
This port is typically not routable over the Internet, most of ISPs are blocking it for security reasons, that's why we can't simply map drive to something like this: \\mylinuxserver.com\myshare.
Also, no other port can be used, as there is no way to force Windows to use some other port other than 139.
Here is simple solution:
Rinetd, (compiled Windows version can be downloaded here) does very simple Port Redirection.
Example: Let's assume that you run SAMBA on your Linux server mylinuxserver.com on port 8844 (instead of 139, for security reasons). All that needs to be done to access SAMBA server shares on your local Windows desktop, is to somehow redirect all TCP/IP traffic that goes to port 139 on your local IP, to mylinuxserver.com:8844.
Now, port 139 on your desktop's local IP is already in use by Windows OS. We need a new virtual local IP (e.g. 10.0.0.1) with port 139 not used.
One of the ways to create new IP, is to install Microsoft Loopback adapter.
The Microsoft Loopback adapter is a testing tool for a virtual network environment where network access is not available. Also, you must use the Loopback adapter if there are conflicts with a network adapter or with a network adapter driver. You can bind network clients, protocols, and other network configuration items to the Loopback adapter, and you can install the network adapter driver or network adapter later while retaining the network configuration information.
- Click Start, and then click Control Panel.
- If you are in Classic view, click Switch to Category View under Control Panel in the left pane.
- Double-click Printers and Other Hardware, and then click Next.
- Under See Also in the left pane, click Add Hardware,and then click Next.
- Click Yes, I have already connected the hardware, and then click Next.
- At the bottom of the list, click Add a new hardware device, and then click Next.
- Click Install the hardware that I manually select from a list, and then click Next.
- Click Network adapters, and then click Next.
- In the Manufacturer box, click Microsoft.
- In the Network Adapter box, click Microsoft Loopback Adapter, and then click Next.
- Click Finish.
- Edit Properties of the new network connection, and uncheck all protocols except TCP/IP (remove Client for Microsoft Networks and File and Printer Sharing)
- In the TCP/IP properties, "Use the following IP address": 10.0.0.1, and in Advanced TCP/IP Settings, Disable NetBIOS over TCP/IP (under WINS tab).
At this point we should have a local IP address 10.0.0.1 with port 139 available for TCP/IP traffic redirection.
We can run rinetd and redirect the port. All TCP/IP traffic coming to 10.0.0.1:139 should be redirected to mylinuxserver.com:8844.
We need to create a small config file c:\bin\rinetd\rinetd.conf that will contain only one line of text:
10.0.0.1 139 mylinuxserver.com 8844Run rinetd:
c:\bin\rinetd\rinetd.exe -c c:\bin\rinetd\rinetd.confand try to map a network drive. Example:
net use L: \\10.0.0.1\myshare mypassword /USER:username /PERSISTENT:YESOf course myshare, mypassword and username should be replaced by actual values.
Please note, that if you need to map SAMBA shares from more than one SAMBA server, you will need more virtual IP addresses (e.g. 10.0.0.2, 10.0.0.3 etc...) and additional port redirection with Rinetd for each of the SAMBA servers.
Rinetd does not encrypt or compress the data, so if you require secure connection, you will need to use SSH Tunnel instead. It will run slightly slower than rinetd. We've been often using this and other similar solutions in our IT Consulting services for years.
Our Last Five Customers
- WCB, Richmond
- Introduction to Linux
- Bash Beginners Guide
- Perl Programming Basics
- Shell Scripting
- Advanced Shell Scripting
- UNIX Sockets FAQ
- Mastering Regular Expressions
- UNIX Programming Examples
- C Programming (Marshall)
- Data Structures and Algorithms
- Art of UNIX Programming
- Advanced Linux Programming
- Linux Kernel Module Programming
- Linux for Mobile Devices
- Basic Unix Administration