There is a rule of Dina D'Malchuta Dina - the law of the land is valid, providing that it does not conflict directly with Torah laws.
There is a Torah law of Venishmartem lenafshotechem (Devarim 4:15), that one must do what he can to guard his own life. Certainly, when one knows that someone is about to kill him, he is allowed to defend himself and use his gun to kill the other.
Gun control laws vary widely around the world. Supposing someone is unable to obtain a gun legally in his location, would he be permitted to carry a gun illegally for self-defense purposes if he is in a Pikuach Nefesh situation (ex. he needs to travel through Pikuach-Nefesh-dangerous locations)?