LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 11-16-2018, 07:25 AM   #1
Sirius7777
LQ Newbie
 
Registered: Nov 2018
Posts: 10
Blog Entries: 1

Rep: Reputation: Disabled
How to do port forwarding?


i have install vm (ubuntu 16.04) in server using kvm and then install unifi controller. Now i need to access that controller using my laptop not that vm. for that i think i should do port forwarding to access that unifi controller using ip address + port number. but i don't know how to do port forwarding. Can anybody help me to do this task. (note: don't wanna to use ssh port forwarding)

Last edited by Sirius7777; 11-16-2018 at 07:26 AM.
 
Old 11-16-2018, 08:29 AM   #2
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
How is your interface for the VM setup? Bridged or NATted?

If bridged then you just need to allow the port on the firewall.

If NATted then you need to do port forwarding, ex.:

Code:
iptables -t nat -A PREROUTING -p tcp -d <External IP> --dport <Port> -j DNAT --to-destination <System IP>
 
Old 11-16-2018, 09:23 AM   #3
Sirius7777
LQ Newbie
 
Registered: Nov 2018
Posts: 10

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Thank for you replying..
its interface is bridged. could you explain the method of allow the port on the firewall. Sorry to bother you but i am new to this environment.
 
Old 11-16-2018, 12:06 PM   #4
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
For the bridge you will have to setup the firewall on the VM to allow the port you are looking to connect to.
 
Old 11-16-2018, 12:21 PM   #5
Sirius7777
LQ Newbie
 
Registered: Nov 2018
Posts: 10

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Can you tell me the command to this configuration please!?
 
Old 11-16-2018, 01:17 PM   #6
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
This should help
 
Old 11-16-2018, 01:33 PM   #7
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
After you read some, try to figure out the command and post it here. I'll let you know if it is right.
 
Old 11-16-2018, 10:48 PM   #8
minakshisondule
LQ Newbie
 
Registered: Nov 2018
Location: Pune
Posts: 18

Rep: Reputation: Disabled
How to do port forwarding?

Ports are like doors in the wall reserved only for useful traffic, and your router does a good job of automatically configuring most of the ports you need to safely use the Internet. In some cases, however, you need to tell your router to open up a certain port so a program won’t be blocked. This is called port forwarding, and here’s how to do it.

Assign Your Device a Static IP Address
First, you need to gather some information about your network and assign a static IP address to the device you're using. A static IP address is an unchanging number identifying a device on your network, and to forward a port you first need to give your router the static IP address of the device for which you are opening the port.

1. From a computer connected to your network, click Start, and then type cmd into the search field. Press Enter.

2. Type ipconfig /all in the window that pops up. Press Enter.

3. Record the following numbers listed under your network connection (labeled “Local Area Connection” or “Wireless Network Connection”):

IPv4 Address (or IP Address)
Subnet Mask
Default Gateway
DNS Servers

4. To set a static IP address on a Windows 7 or Vista PC, open Control Panel. Click Network and Internet, then Network and Sharing Center. In the left pane, click Change adapter settings in Windows 7; in Vista, click Manage network connections.

4a. Right-click Local Area Connection; then click Properties.

4b. In the list, select Internet Protocol Version 4 (TCP/IPv4), and click Properties.

4c. Select Use the following IP address. Add 10 to the last digit of your Default Gateway number and enter it into the IP address field. For example, if your Default Gateway is 192.168.1.1, the new number is 192.168.1.11.

4d. Enter the numbers of the Subnet Mask, Default Gateway, and DNS Servers that you recorded earlier into their respective fields. Click OK.

5. To assign a static IP to a printer, video game console, or other device on your network, you’ll need to use the device’s control panel or a Web-based interface.

Forward Ports

Now that you have a static IP assigned to your computer or other network device, log in to your router’s interface and open a port.

1. Open a Web browser, type your Default Gateway number into the address bar, and press Enter.

2. Enter your username and password to access your router’s interface. The default username and password should be listed in your router’s documentation, on a sticker on the side of your router, or on the Port Forward website. If the username and password have been changed from the defaults and you don’t remember them, you’ll need to reset your router.

3. To forward ports on your router, look for a tab or menu labeled “Applications & Gaming,” “Advanced,” “Port Forwarding/Port Triggering,” “NAT/QoS,” or something similar.

4. No matter what the router or interface, you’ll need to enter the same basic information. Enter the port you want to open under Internal and External, or enter a range of ports to open under Start and End. If you aren’t sure what port(s) you need to open for an application, consult this Port Forward list. Some common ports are 25565 (Minecraft), 6881–6887 (BitTorrent clients), and 3724 (World of Warcraft).

5. Choose the Protocol (TCP, UDP, or both).

6. Enter the static IP address you created.

7. Be sure Enable is selected if available. Enter a name under Application if you want, then save the changes.

Hope this will be helpful to you..
 
Old 11-18-2018, 10:23 PM   #9
Sirius7777
LQ Newbie
 
Registered: Nov 2018
Posts: 10

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by lazydog View Post
After you read some, try to figure out the command and post it here. I'll let you know if it is right.
Sorry for the late reply:
According to your given link i used that commands and i am showing command and its output please review it and tell me it is right or wrong.

$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- anywhere anywhere udp dpt:domain
ACCEPT tcp -- anywhere anywhere tcp dpt:domain
ACCEPT udp -- anywhere anywhere udp dpt:bootps
ACCEPT tcp -- anywhere anywhere tcp dpt:bootps

Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere 192.168.122.0/24 ctstate RELATED,ESTABLISHED
ACCEPT all -- 192.168.122.0/24 anywhere
ACCEPT all -- anywhere anywhere
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- anywhere anywhere udp dpt:bootpc

# firewall-cmd --permanent --add-port=8443/tcp

it is not accepting this command? this is first command

Last edited by Sirius7777; 11-18-2018 at 11:01 PM.
 
Old 11-19-2018, 01:32 AM   #10
Sirius7777
LQ Newbie
 
Registered: Nov 2018
Posts: 10

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Hello,
Let me explain to you my task. My task is I have vm (Ubuntu 16.04) on my server and I have install unifi controller on it (unifi controller address is https://localhost:8443) now I want to access unifi controller from my laptop that have install on vm using port forwarding. Could you explain its method please?

Anybody can help me with in this?
 
Old 11-19-2018, 10:43 AM   #11
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by Sirius7777 View Post
Sorry for the late reply:
According to your given link i used that commands and i am showing command and its output please review it and tell me it is right or wrong.

$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- anywhere anywhere udp dpt:domain
ACCEPT tcp -- anywhere anywhere tcp dpt:domain
ACCEPT udp -- anywhere anywhere udp dpt:bootps
ACCEPT tcp -- anywhere anywhere tcp dpt:bootps

Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere 192.168.122.0/24 ctstate RELATED,ESTABLISHED
ACCEPT all -- 192.168.122.0/24 anywhere
ACCEPT all -- anywhere anywhere
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- anywhere anywhere udp dpt:bootpc

# firewall-cmd --permanent --add-port=8443/tcp

it is not accepting this command? this is first command
While that commend shows you what is allowed and dropped in the firewall I like seeing the rule them selves with this comend:

Code:
iptables -S
What you are showing me is that your firewall is wide open and accepting everything. So the firewall is not stopping you from connecting to port 8443.

Quote:
Originally Posted by Sirius7777 View Post
Hello,
Let me explain to you my task. My task is I have vm (Ubuntu 16.04) on my server and I have install unifi controller on it (unifi controller address is https://localhost:8443) now I want to access unifi controller from my laptop that have install on vm using port forwarding. Could you explain its method please?

Anybody can help me with in this?
OK run this command on both the real server and the VM for me and post the output.

Code:
iptables -S
 
Old 11-19-2018, 10:17 PM   #12
Sirius7777
LQ Newbie
 
Registered: Nov 2018
Posts: 10

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
here is the result of iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A INPUT -i virbr0 -p udp -m udp --dport 53 -j ACCEPT
-A INPUT -i virbr0 -p tcp -m tcp --dport 53 -j ACCEPT
-A INPUT -i virbr0 -p udp -m udp --dport 67 -j ACCEPT
-A INPUT -i virbr0 -p tcp -m tcp --dport 67 -j ACCEPT
-A INPUT -i virbr0 -p udp -m udp --dport 53 -j ACCEPT
-A INPUT -i virbr0 -p tcp -m tcp --dport 53 -j ACCEPT
-A INPUT -i virbr0 -p udp -m udp --dport 67 -j ACCEPT
-A INPUT -i virbr0 -p tcp -m tcp --dport 67 -j ACCEPT
-A INPUT -i ens9 -p tcp -m tcp --dport 8443 -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A FORWARD -d 192.168.122.0/24 -o virbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -s 192.168.122.0/24 -i virbr0 -j ACCEPT
-A FORWARD -i virbr0 -o virbr0 -j ACCEPT
-A FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -d 192.168.122.0/24 -o virbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -s 192.168.122.0/24 -i virbr0 -j ACCEPT
-A FORWARD -i virbr0 -o virbr0 -j ACCEPT
-A FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
-A OUTPUT -o virbr0 -p udp -m udp --dport 68 -j ACCEPT
-A OUTPUT -o virbr0 -p udp -m udp --dport 68 -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
 
Old 11-20-2018, 06:14 AM   #13
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
You have a lot of repeating lines in this setup. As stated before it doesn't look like you are blocking the port. Which device is this firewall deployed on?

Lines in RED are not needed as they are duplicates.

Quote:
Originally Posted by Sirius7777 View Post
here is the result of iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A INPUT -i virbr0 -p udp -m udp --dport 53 -j ACCEPT
-A INPUT -i virbr0 -p tcp -m tcp --dport 53 -j ACCEPT
-A INPUT -i virbr0 -p udp -m udp --dport 67 -j ACCEPT
-A INPUT -i virbr0 -p tcp -m tcp --dport 67 -j ACCEPT
-A INPUT -i virbr0 -p udp -m udp --dport 53 -j ACCEPT
-A INPUT -i virbr0 -p tcp -m tcp --dport 53 -j ACCEPT
-A INPUT -i virbr0 -p udp -m udp --dport 67 -j ACCEPT
-A INPUT -i virbr0 -p tcp -m tcp --dport 67 -j ACCEPT

-A INPUT -i ens9 -p tcp -m tcp --dport 8443 -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A FORWARD -d 192.168.122.0/24 -o virbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -s 192.168.122.0/24 -i virbr0 -j ACCEPT
-A FORWARD -i virbr0 -o virbr0 -j ACCEPT
-A FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -d 192.168.122.0/24 -o virbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -s 192.168.122.0/24 -i virbr0 -j ACCEPT
-A FORWARD -i virbr0 -o virbr0 -j ACCEPT

-A FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
-A OUTPUT -o virbr0 -p udp -m udp --dport 68 -j ACCEPT
-A OUTPUT -o virbr0 -p udp -m udp --dport 68 -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
I need the firewall from both devices. I'm suspecting that the Ubuntu is where the blocking is taken place.
 
Old 11-20-2018, 06:37 AM   #14
Sirius7777
LQ Newbie
 
Registered: Nov 2018
Posts: 10

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by lazydog View Post
You have a lot of repeating lines in this setup. As stated before it doesn't look like you are blocking the port. Which device is this firewall deployed on?

Lines in RED are not needed as they are duplicates.

Sorry but according to my senior he command me to delete all iptables so i flush all chain now could you explain me the step......

I need the firewall from both devices. I'm suspecting that the Ubuntu is where the blocking is taken place.
and my first device is Ubuntu vm is installed in kvm of server where is unifi controller is installed and i wanna to access Unifi_controller from my windows 10 laptop......
 
Old 11-20-2018, 08:13 AM   #15
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by Sirius7777 View Post
and my first device is Ubuntu vm is installed in kvm of server where is unifi controller is installed and i wanna to access Unifi_controller from my windows 10 laptop......
So the firewall config above is from the Ubuntu server which is a VM correct?

If that is the case is there any other firewall/ACL in front of that?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] IPtables : ssh port forwarding one port to another port issue routers Linux - Networking 7 08-07-2018 08:41 AM
Redirec port in device eth0 to port+ip in device wlan0 ( port forwarding on hostpd wireless network) MattFly Linux - Networking 2 08-28-2016 07:21 PM
Shorewall: port forwarding problem, port is closed even after forwarding Synt4x_3rr0r Linux - Networking 2 12-13-2009 04:36 PM
IPCHAINS port forwarding and IPTABLES port forwarding ediestajr Linux - Networking 26 01-14-2007 07:35 PM
port forwarding and packet forwarding syrtsardo Linux - Newbie 2 07-03-2003 10:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 07:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration