Forward incoming request from specific ip to a local ip and port in ubuntu - iptables

I have assigned a local Ip 192.168.1.253 to an instance(Openstack instance) running on my machine. The Ip address of my physical machine on the local network is 10.59.1.150, I can access 10.59.1.150 from my internal network. I want to redirect the incoming requests of 10.59.1.150:4000 to 192.168.1.253:4000.
Is there any way to do it?

The problem was resolved using:
sysctl net.ipv4.ip_forward=1
Link: http://jensd.be/343/linux/forward-a-tcp-port-to-another-ip-or-port-using-nat-with-iptables

Related

isc-dhcp-server not work in openstack's instance but work in vmware

Through tcpdump in dhcp-server, it shows the server can receive the DHCPDISCOVER package and send the DHCPOFFER package, but can not receive the DHCPREQUEST package from the dhcp-client, so the client can not get IP address and always in send DHCPDISCOVER package.
But the dhcp-server which runs in VMWARE's instance can send DHCPACK to client and the same client will get the IP success. The dhcp-server using the same configure as in Openstack's instance.
And, if I configure the static IP address in the client instance, it will ping the dhcp-server's IP successful.
One more thing, the server and client are in the same vlan.
Is there any limit rule in Openstack's instance? How can I resolve this problem, THX.
The essential reason is that the traffic of port is limited by the security groups in openstack.
By default, all security groups contain a series of basic (sanity) and anti-spoofing rules that perform the following actions:
Deny egress DHCP and DHCPv6 responses to prevent instances from acting as DHCP(v6) servers.
Resolution:
disable security groups (no recommend)
set dhcp-relay to the dhcp server in router (recommend)
security groups limited the traffic by hypervisor's iptables which will drop the packets which's src port is 67 and dst port is 68.
DHCPOFFER packets will send to router by src and dst port 67, and it will works to all vlans.
For DHCP relay and DHCP proxy, packets sent to the DHCP server from the router have both the source and destination UDP ports set to 67. The DHCP server responds using the same ports.
Maybe there are some methods but I can't find out until now ?

How do I find the IP address to use in an HTTP request?

I want to make an http request via the fetch() method in React Native, and I need the IP address of the machine I'm sending the request to. I have access to the machine, and googled "what's my IP" on it. It said my public IP was 162.250.198.98, but when I googled it on another computer nearby, it gave the same address. Is this the right IP to use in a fetch request like this? If not, how do I find the right one to use?
If you have multiple machines connected to the internet via a NAT-enabled router, they will all share the same public IP address. You need to forward a specific port to the machine you want to connect to in the router's configuration e.g. to send your request on port 5000, add a rule to the router to forward port 5000 to your desired machine, then send the request to 162.250.198.98:5000
For your application to work you need a "server" with a public ip address. Later you assign a domain name to that server/ip address ex. api.domain.com
Since you don't have a server and you are using your computer to test your development, you can do this 2 options:
Use your computer IP address usually 192.168.x.x , 10.x.x.x or 172.16.x.x This will allow you to test it if your phone is connected wireless to the same network.
Since you are behind a NAT you can do a port forward to send the traffic to X port to your desired host(ip/port) behind the nat. Usually we create API's that run on port 80 or 443 do a port forward in your router to pass the traffic from this port to your computer ip/port.

Unable to ping to a host

I'm able to ssh to a host from my machine but when I try to ping the host from my machine, it says 100% packet loss !!
So my query is that what all could be the possible reasons behind this behavior (able to SSH but unable to PING through the same machine).
NOTE: All communication were tried using IP address of the target host.
Two common reasons:
Firewall. in local host, target host, or somewhere in route between hosts.
ICMP echo responsing is disabled in the target host.
If DNS query is used, ping and ssh tools may select different IP from the response. For example ping may select IPv6 address, and ssh IPv4 address. --> Try tools with IP addresses instead of host names.

Can't connect despite port forwarding

I have a Ubuntu Server 16.04 running on a machine in my local network.
The machine has static assigned IP and running apache2. There is no problem in connecting to it from my local network.
I have port-forwarding for ports 22 and 80 setup on my router to the IP address of the machine.
When I check the ports with my public IP address on sites like http://www.canyouseeme.org/ the result is that the ports are open. When I try to connect using my public IP address and using those ports the connections are refused.
I tried disabling firewall in the router and also on the machine, no result.
What else should I try? It seems that the server is getting no incoming connection when I check with netstat.
Just for troubleshooting purposes:
Setup port forwarding on port 22 and try to ssh into your server using the public IP? If it works, it means apache is refusing the connections and not your router or ISP
On your router, setup the server on the DMZ temporarily and check if it works
Add another port forwarding rule on your router to redirect all http requests on port 8000,for example, to port 80 internally, then try to access your server with http://[public_ip]:8000
Have you changed anything on the apache2.conf file? Also, explain how you are testing the connection, internally using the public IP or from the Internet?

How to access a web server installed on Hyper-V

I have installed Ubuntu on Windows 8 using Hyper V. Having also installed Apache 2 I had the notion that I was going to use this as a web dev environment. I set up an external switch so that my ubuntu installation could access the internet. So far everything was progressing swimmingly. The problem I am encountering is that I have no idea how to access the web server from my machine. I can get the IP address that ubuntu picks up and type that into my browser whereupon I am informed "It works!". That's all good but I move around among several networks and I should not have to look up the IP address every time, and that can't facilitate having multiple sites installed. I just want to be able to enter something like
"http://mytestserver/"
into my browser to access it.
Any pointers on how to set this up properly would be much appreciated.
I have always had the most success with Bridged networking in VM Guests and would definitley recommend you go with that option. What you then could do and what I have done is to assign a static IP for the server and assign the hostname as below. You will have to know what IP addressing is available or you can use 192.168.1.x if your inside your network.
The easiest way would be to assign a static IP in /etc/network/interfaces replacing the 0.0.0.0 with the correct entries for your network
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 0.0.0.0.0
netmask 0.0.0.0.0
gateway 0.0.0.0.0
broadcast 0.0.0.0.0
dns-nameservers 0.0.0.0.0 0.0.0.0.0
and then edit your /etc/hosts file and add that static IP and add the Hostname mytestserver. You will already have the localhost entry and possibly others. Just make sure you assign the Static IP address you assigned in interfaces to mytestserver. You may also have to make this same entry in your machines hosts file simply because it will not have a DNS record.
127.0.0.1 localhost
0.0.0.0 mytestserver