making a SSH to Deny connections from all IP's except selected












1














So i made a SSH server and i want it to deny all incoming connections from all ip's except a few. local ip's and my phone 3G public ip...the problem is after a set of iptable rules i only can connect with my phone and not my pc or the virtual machine connected on same network via LAN.



so i have tried



/etc/hosts.allow /etc/hosts.deny



and decided iptables would be best here. and did



iptables -A INPUT -m state --state NEW,ESTABLISHED,RELATED --source x.x.x.x -p tcp --dport myport -j ACCEPT


a few times with different ip's i want to have access to my ssh server. I entered the LAN IP's of my PC and a virtual machine i had up and running and the phone LAN and PUBLIC. next command was



iptables -A INPUT -m state --state NEW,ESTABLISHED,RELATED -p tcp --dport myport -j DROP


after that i can access the SSH via my phone both lan and public ip's but not the PC and the virtual machine. i have no clue on usage of iptables so would appriciate some help. I tried reading alot here but didn't find the answer i need.



The server distro is UBUNTU.18 and my pc an arch.





a hour later...well i checked my firewall rules and everything looks right. i even tried connecting this pc to vpn and allowing the vpn ip for testing. but as long i do it from a pc it doesn't work. works perfectly with the phone but the pc gets blocked somehow..and i get the same result using /etc/hosts.deny and /etc/hosts.allow if i delete the rules of iptables.










share|improve this question









New contributor




Alexis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 2




    Possible duplicate of Limit SSH access to specific clients by IP address
    – roaima
    1 hour ago










  • did you remove the host.allow/deny?
    – danblack
    33 mins ago










  • what i did was commenting out everything in hosts.allow and deny with #
    – Alexis
    29 mins ago
















1














So i made a SSH server and i want it to deny all incoming connections from all ip's except a few. local ip's and my phone 3G public ip...the problem is after a set of iptable rules i only can connect with my phone and not my pc or the virtual machine connected on same network via LAN.



so i have tried



/etc/hosts.allow /etc/hosts.deny



and decided iptables would be best here. and did



iptables -A INPUT -m state --state NEW,ESTABLISHED,RELATED --source x.x.x.x -p tcp --dport myport -j ACCEPT


a few times with different ip's i want to have access to my ssh server. I entered the LAN IP's of my PC and a virtual machine i had up and running and the phone LAN and PUBLIC. next command was



iptables -A INPUT -m state --state NEW,ESTABLISHED,RELATED -p tcp --dport myport -j DROP


after that i can access the SSH via my phone both lan and public ip's but not the PC and the virtual machine. i have no clue on usage of iptables so would appriciate some help. I tried reading alot here but didn't find the answer i need.



The server distro is UBUNTU.18 and my pc an arch.





a hour later...well i checked my firewall rules and everything looks right. i even tried connecting this pc to vpn and allowing the vpn ip for testing. but as long i do it from a pc it doesn't work. works perfectly with the phone but the pc gets blocked somehow..and i get the same result using /etc/hosts.deny and /etc/hosts.allow if i delete the rules of iptables.










share|improve this question









New contributor




Alexis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 2




    Possible duplicate of Limit SSH access to specific clients by IP address
    – roaima
    1 hour ago










  • did you remove the host.allow/deny?
    – danblack
    33 mins ago










  • what i did was commenting out everything in hosts.allow and deny with #
    – Alexis
    29 mins ago














1












1








1







So i made a SSH server and i want it to deny all incoming connections from all ip's except a few. local ip's and my phone 3G public ip...the problem is after a set of iptable rules i only can connect with my phone and not my pc or the virtual machine connected on same network via LAN.



so i have tried



/etc/hosts.allow /etc/hosts.deny



and decided iptables would be best here. and did



iptables -A INPUT -m state --state NEW,ESTABLISHED,RELATED --source x.x.x.x -p tcp --dport myport -j ACCEPT


a few times with different ip's i want to have access to my ssh server. I entered the LAN IP's of my PC and a virtual machine i had up and running and the phone LAN and PUBLIC. next command was



iptables -A INPUT -m state --state NEW,ESTABLISHED,RELATED -p tcp --dport myport -j DROP


after that i can access the SSH via my phone both lan and public ip's but not the PC and the virtual machine. i have no clue on usage of iptables so would appriciate some help. I tried reading alot here but didn't find the answer i need.



The server distro is UBUNTU.18 and my pc an arch.





a hour later...well i checked my firewall rules and everything looks right. i even tried connecting this pc to vpn and allowing the vpn ip for testing. but as long i do it from a pc it doesn't work. works perfectly with the phone but the pc gets blocked somehow..and i get the same result using /etc/hosts.deny and /etc/hosts.allow if i delete the rules of iptables.










share|improve this question









New contributor




Alexis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











So i made a SSH server and i want it to deny all incoming connections from all ip's except a few. local ip's and my phone 3G public ip...the problem is after a set of iptable rules i only can connect with my phone and not my pc or the virtual machine connected on same network via LAN.



so i have tried



/etc/hosts.allow /etc/hosts.deny



and decided iptables would be best here. and did



iptables -A INPUT -m state --state NEW,ESTABLISHED,RELATED --source x.x.x.x -p tcp --dport myport -j ACCEPT


a few times with different ip's i want to have access to my ssh server. I entered the LAN IP's of my PC and a virtual machine i had up and running and the phone LAN and PUBLIC. next command was



iptables -A INPUT -m state --state NEW,ESTABLISHED,RELATED -p tcp --dport myport -j DROP


after that i can access the SSH via my phone both lan and public ip's but not the PC and the virtual machine. i have no clue on usage of iptables so would appriciate some help. I tried reading alot here but didn't find the answer i need.



The server distro is UBUNTU.18 and my pc an arch.





a hour later...well i checked my firewall rules and everything looks right. i even tried connecting this pc to vpn and allowing the vpn ip for testing. but as long i do it from a pc it doesn't work. works perfectly with the phone but the pc gets blocked somehow..and i get the same result using /etc/hosts.deny and /etc/hosts.allow if i delete the rules of iptables.







ssh iptables






share|improve this question









New contributor




Alexis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Alexis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 20 mins ago









Rui F Ribeiro

39.4k1479131




39.4k1479131






New contributor




Alexis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 hours ago









AlexisAlexis

62




62




New contributor




Alexis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Alexis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Alexis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 2




    Possible duplicate of Limit SSH access to specific clients by IP address
    – roaima
    1 hour ago










  • did you remove the host.allow/deny?
    – danblack
    33 mins ago










  • what i did was commenting out everything in hosts.allow and deny with #
    – Alexis
    29 mins ago














  • 2




    Possible duplicate of Limit SSH access to specific clients by IP address
    – roaima
    1 hour ago










  • did you remove the host.allow/deny?
    – danblack
    33 mins ago










  • what i did was commenting out everything in hosts.allow and deny with #
    – Alexis
    29 mins ago








2




2




Possible duplicate of Limit SSH access to specific clients by IP address
– roaima
1 hour ago




Possible duplicate of Limit SSH access to specific clients by IP address
– roaima
1 hour ago












did you remove the host.allow/deny?
– danblack
33 mins ago




did you remove the host.allow/deny?
– danblack
33 mins ago












what i did was commenting out everything in hosts.allow and deny with #
– Alexis
29 mins ago




what i did was commenting out everything in hosts.allow and deny with #
– Alexis
29 mins ago










0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Alexis is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493833%2fmaking-a-ssh-to-deny-connections-from-all-ips-except-selected%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes








Alexis is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Alexis is a new contributor. Be nice, and check out our Code of Conduct.













Alexis is a new contributor. Be nice, and check out our Code of Conduct.












Alexis is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493833%2fmaking-a-ssh-to-deny-connections-from-all-ips-except-selected%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Entries order in /etc/network/interfaces

Grub takes very long (several minutes) to open Menu (in Multi-Boot-System)

新発田市